1
2 /*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.android.launcher3;
19
20 import android.animation.Animator;
21 import android.animation.AnimatorListenerAdapter;
22 import android.animation.AnimatorSet;
23 import android.animation.ObjectAnimator;
24 import android.animation.PropertyValuesHolder;
25 import android.animation.TimeInterpolator;
26 import android.animation.ValueAnimator;
27 import android.annotation.TargetApi;
28 import android.app.Activity;
29 import android.app.ActivityManager;
30 import android.app.ActivityOptions;
31 import android.app.AlertDialog;
32 import android.app.SearchManager;
33 import android.appwidget.AppWidgetHostView;
34 import android.appwidget.AppWidgetManager;
35 import android.appwidget.AppWidgetProviderInfo;
36 import android.content.ActivityNotFoundException;
37 import android.content.BroadcastReceiver;
38 import android.content.ComponentCallbacks2;
39 import android.content.ComponentName;
40 import android.content.ContentResolver;
41 import android.content.Context;
42 import android.content.DialogInterface;
43 import android.content.Intent;
44 import android.content.IntentFilter;
45 import android.content.SharedPreferences;
46 import android.content.pm.ActivityInfo;
47 import android.content.pm.ApplicationInfo;
48 import android.content.pm.PackageManager;
49 import android.content.pm.PackageManager.NameNotFoundException;
50 import android.content.res.Configuration;
51 import android.content.res.Resources;
52 import android.database.ContentObserver;
53 import android.graphics.Bitmap;
54 import android.graphics.Canvas;
55 import android.graphics.Color;
56 import android.graphics.Point;
57 import android.graphics.PorterDuff;
58 import android.graphics.Rect;
59 import android.graphics.drawable.Drawable;
60 import android.net.Uri;
61 import android.os.AsyncTask;
62 import android.os.Build;
63 import android.os.Bundle;
64 import android.os.Environment;
65 import android.os.Handler;
66 import android.os.Message;
67 import android.os.StrictMode;
68 import android.os.SystemClock;
69 import android.speech.RecognizerIntent;
70 import android.text.Selection;
71 import android.text.SpannableStringBuilder;
72 import android.text.TextUtils;
73 import android.text.method.TextKeyListener;
74 import android.util.DisplayMetrics;
75 import android.util.Log;
76 import android.view.ContextThemeWrapper;
77 import android.view.Display;
78 import android.view.Gravity;
79 import android.view.HapticFeedbackConstants;
80 import android.view.KeyEvent;
81 import android.view.LayoutInflater;
82 import android.view.Menu;
83 import android.view.MotionEvent;
84 import android.view.Surface;
85 import android.view.View;
86 import android.view.View.OnClickListener;
87 import android.view.View.OnLongClickListener;
88 import android.view.ViewAnimationUtils;
89 import android.view.ViewGroup;
90 import android.view.ViewTreeObserver;
91 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
92 import android.view.Window;
93 import android.view.WindowManager;
94 import android.view.accessibility.AccessibilityEvent;
95 import android.view.animation.AccelerateInterpolator;
96 import android.view.animation.DecelerateInterpolator;
97 import android.view.animation.Interpolator;
98 import android.view.inputmethod.InputMethodManager;
99 import android.widget.Advanceable;
100 import android.widget.FrameLayout;
101 import android.widget.ImageView;
102 import android.widget.TextView;
103 import android.widget.Toast;
104
105 import com.android.launcher3.DropTarget.DragObject;
106 import com.android.launcher3.PagedView.PageSwitchListener;
107 import com.android.launcher3.compat.AppWidgetManagerCompat;
108 import com.android.launcher3.compat.LauncherActivityInfoCompat;
109 import com.android.launcher3.compat.LauncherAppsCompat;
110 import com.android.launcher3.compat.PackageInstallerCompat;
111 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
112 import com.android.launcher3.compat.UserHandleCompat;
113 import com.android.launcher3.compat.UserManagerCompat;
114
115 import java.io.DataInputStream;
116 import java.io.DataOutputStream;
117 import java.io.File;
118 import java.io.FileDescriptor;
119 import java.io.FileNotFoundException;
120 import java.io.FileOutputStream;
121 import java.io.IOException;
122 import java.io.PrintWriter;
123 import java.lang.reflect.Field;
124 import java.lang.reflect.InvocationTargetException;
125 import java.lang.reflect.Method;
126 import java.text.DateFormat;
127 import java.util.ArrayList;
128 import java.util.Collection;
129 import java.util.Date;
130 import java.util.HashMap;
131 import java.util.List;
132 import java.util.concurrent.atomic.AtomicInteger;
133
134 /**
135 * Default launcher application.
136 */
137 public class Launcher extends Activity
138 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
139 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
140 static final String TAG = "Launcher";
141 static final boolean LOGD = false;
142
143 static final boolean PROFILE_STARTUP = false;
144 static final boolean DEBUG_WIDGETS = false;
145 static final boolean DEBUG_STRICT_MODE = false;
146 static final boolean DEBUG_RESUME_TIME = false;
147 static final boolean DEBUG_DUMP_LOG = false;
148
149 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
150
151 private static final int REQUEST_CREATE_SHORTCUT = 1;
152 private static final int REQUEST_CREATE_APPWIDGET = 5;
153 private static final int REQUEST_PICK_SHORTCUT = 7;
154 private static final int REQUEST_PICK_APPWIDGET = 9;
155 private static final int REQUEST_PICK_WALLPAPER = 10;
156
157 private static final int REQUEST_BIND_APPWIDGET = 11;
158 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
159
160 /**
161 * IntentStarter uses request codes starting with this. This must be greater than all activity
162 * request codes used internally.
163 */
164 protected static final int REQUEST_LAST = 100;
165
166 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
167
168 static final int SCREEN_COUNT = 5;
169 static final int DEFAULT_SCREEN = 2;
170
171 private static final String PREFERENCES = "launcher.preferences";
172 // To turn on these properties, type
173 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
174 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
175 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
176 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
177
178 // The Intent extra that defines whether to ignore the launch animation
179 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
180 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
181
182 // Type: int
183 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
184 // Type: int
185 private static final String RUNTIME_STATE = "launcher.state";
186 // Type: int
187 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
188 // Type: int
189 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
190 // Type: int
191 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
192 // Type: int
193 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
194 // Type: boolean
195 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
196 // Type: long
197 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
198 // Type: int
199 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
200 // Type: int
201 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
202 // Type: parcelable
203 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
204 // Type: parcelable
205 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
206 // Type: int[]
207 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
208
209 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
210 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
211
212 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
213 static final String ACTION_FIRST_LOAD_COMPLETE =
214 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
215
216 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
217 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
218 "com.android.launcher.toolbar_search_icon";
219 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
220 "com.android.launcher.toolbar_voice_search_icon";
221
222 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
223 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
224
225 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
226
227 /** The different states that Launcher can be in. */
228 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
229 private State mState = State.WORKSPACE;
230 private AnimatorSet mStateAnimation;
231
232 private boolean mIsSafeModeEnabled;
233
234 static final int APPWIDGET_HOST_ID = 1024;
235 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
236 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
237 private static final int ACTIVITY_START_DELAY = 1000;
238
239 private static final Object sLock = new Object();
240 private static int sScreen = DEFAULT_SCREEN;
241
242 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
243 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
244
245 // How long to wait before the new-shortcut animation automatically pans the workspace
246 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
247 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
248 private static int NEW_APPS_ANIMATION_DELAY = 500;
249 private static final int SINGLE_FRAME_DELAY = 16;
250
251 private final BroadcastReceiver mCloseSystemDialogsReceiver
252 = new CloseSystemDialogsIntentReceiver();
253 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
254
255 private LayoutInflater mInflater;
256
257 private Workspace mWorkspace;
258 private View mLauncherView;
259 private View mPageIndicators;
260 private DragLayer mDragLayer;
261 private DragController mDragController;
262 private View mWeightWatcher;
263
264 private AppWidgetManagerCompat mAppWidgetManager;
265 private LauncherAppWidgetHost mAppWidgetHost;
266
267 private ItemInfo mPendingAddInfo = new ItemInfo();
268 private AppWidgetProviderInfo mPendingAddWidgetInfo;
269 private int mPendingAddWidgetId = -1;
270
271 private int[] mTmpAddItemCellCoordinates = new int[2];
272
273 private FolderInfo mFolderInfo;
274
275 private Hotseat mHotseat;
276 private ViewGroup mOverviewPanel;
277
278 private View mAllAppsButton;
279
280 private SearchDropTargetBar mSearchDropTargetBar;
281 private AppsCustomizeTabHost mAppsCustomizeTabHost;
282 private AppsCustomizePagedView mAppsCustomizeContent;
283 private boolean mAutoAdvanceRunning = false;
284 private View mQsb;
285
286 private Bundle mSavedState;
287 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
288 // scroll issues (because the workspace may not have been measured yet) and extra work.
289 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
290 private State mOnResumeState = State.NONE;
291
292 private SpannableStringBuilder mDefaultKeySsb = null;
293
294 private boolean mWorkspaceLoading = true;
295
296 private boolean mPaused = true;
297 private boolean mRestoring;
298 private boolean mWaitingForResult;
299 private boolean mOnResumeNeedsLoad;
300
301 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
302 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
303
304 private Bundle mSavedInstanceState;
305
306 private LauncherModel mModel;
307 private IconCache mIconCache;
308 private boolean mUserPresent = true;
309 private boolean mVisible = false;
310 private boolean mHasFocus = false;
311 private boolean mAttached = false;
312
313 private static LocaleConfiguration sLocaleConfiguration = null;
314
315 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
316
317 private View.OnTouchListener mHapticFeedbackTouchListener;
318
319 // Related to the auto-advancing of widgets
320 private final int ADVANCE_MSG = 1;
321 private final int mAdvanceInterval = 20000;
322 private final int mAdvanceStagger = 250;
323 private long mAutoAdvanceSentTime;
324 private long mAutoAdvanceTimeLeft = -1;
325 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
326 new HashMap<View, AppWidgetProviderInfo>();
327
328 // Determines how long to wait after a rotation before restoring the screen orientation to
329 // match the sensor state.
330 private final int mRestoreScreenOrientationDelay = 500;
331
332 // External icons saved in case of resource changes, orientation, etc.
333 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
334 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
335
336 private Drawable mWorkspaceBackgroundDrawable;
337
338 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
339 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
340
341 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
342 static Date sDateStamp = new Date();
343 static DateFormat sDateFormat =
344 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
345 static long sRunStart = System.currentTimeMillis();
346 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
347
348 // We only want to get the SharedPreferences once since it does an FS stat each time we get
349 // it from the context.
350 private SharedPreferences mSharedPrefs;
351
352 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
353
354 // Holds the page that we need to animate to, and the icon views that we need to animate up
355 // when we scroll to that page on resume.
356 private ImageView mFolderIconImageView;
357 private Bitmap mFolderIconBitmap;
358 private Canvas mFolderIconCanvas;
359 private Rect mRectForFolderAnimation = new Rect();
360
361 private BubbleTextView mWaitingForResume;
362
363 private Runnable mBuildLayersRunnable = new Runnable() {
364 public void run() {
365 if (mWorkspace != null) {
366 mWorkspace.buildPageHardwareLayers();
367 }
368 }
369 };
370
371 private static PendingAddArguments sPendingAddItem;
372
373 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
374
375 private static class PendingAddArguments {
376 int requestCode;
377 Intent intent;
378 long container;
379 long screenId;
380 int cellX;
381 int cellY;
382 int appWidgetId;
383 }
384
385 private Stats mStats;
386
387 FocusIndicatorView mFocusHandler;
388
389 static boolean isPropertyEnabled(String propertyName) {
390 return Log.isLoggable(propertyName, Log.VERBOSE);
391 }
392
393 @Override
394 protected void onCreate(Bundle savedInstanceState) {
395 if (DEBUG_STRICT_MODE) {
396 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
397 .detectDiskReads()
398 .detectDiskWrites()
399 .detectNetwork() // or .detectAll() for all detectable problems
400 .penaltyLog()
401 .build());
402 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
403 .detectLeakedSqlLiteObjects()
404 .detectLeakedClosableObjects()
405 .penaltyLog()
406 .penaltyDeath()
407 .build());
408 }
409
410 super.onCreate(savedInstanceState);
411
412 LauncherAppState.setApplicationContext(getApplicationContext());
413 LauncherAppState app = LauncherAppState.getInstance();
414 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
415 // Determine the dynamic grid properties
416 Point smallestSize = new Point();
417 Point largestSize = new Point();
418 Point realSize = new Point();
419 Display display = getWindowManager().getDefaultDisplay();
420 display.getCurrentSizeRange(smallestSize, largestSize);
421 display.getRealSize(realSize);
422 DisplayMetrics dm = new DisplayMetrics();
423 display.getMetrics(dm);
424
425 // Lazy-initialize the dynamic grid
426 DeviceProfile grid = app.initDynamicGrid(this,
427 Math.min(smallestSize.x, smallestSize.y),
428 Math.min(largestSize.x, largestSize.y),
429 realSize.x, realSize.y,
430 dm.widthPixels, dm.heightPixels);
431
432 // the LauncherApplication should call this, but in case of Instrumentation it might not be prese🔵
433 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
434 Context.MODE_PRIVATE);
435 mIsSafeModeEnabled = getPackageManager().isSafeMode();
436 mModel = app.setLauncher(this);
437 mIconCache = app.getIconCache();
438 mIconCache.flushInvalidIcons(grid);
439 mDragController = new DragController(this);
440 mInflater = getLayoutInflater();
441
442 mStats = new Stats(this);
443
444 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
445
446 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
447 mAppWidgetHost.startListening();
448
449 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
450 // this also ensures that any synchronous binding below doesn't re-trigger another
451 // LauncherModel load.
452 mPaused = false;
453
454 if (PROFILE_STARTUP) {
455 android.os.Debug.startMethodTracing(
456 Environment.getExternalStorageDirectory() + "/launcher");
457 }
458
459 checkForLocaleChange();
460 setContentView(R.layout.launcher);
461
462 setupViews();
463 grid.layout(this);
464
465 registerContentObservers();
466
467 lockAllApps();
468
469 mSavedState = savedInstanceState;
470 restoreState(mSavedState);
471
472 if (PROFILE_STARTUP) {
473 android.os.Debug.stopMethodTracing();
474 }
475
476 if (!mRestoring) {
477 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
478 // If the user leaves launcher, then we should just load items asynchronously when
479 // they return.
480 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
481 } else {
482 // We only load the page synchronously if the user rotates (or triggers a
483 // configuration change) while launcher is in the foreground
484 mModel.startLoader(true, mWorkspace.getRestorePage());
485 }
486 }
487
488 // For handling default keys
489 mDefaultKeySsb = new SpannableStringBuilder();
490 Selection.setSelection(mDefaultKeySsb, 0);
491
492 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
493 registerReceiver(mCloseSystemDialogsReceiver, filter);
494
495 updateGlobalIcons();
496
497 // On large interfaces, we want the screen to auto-rotate based on the current orientation
498 unlockScreenOrientation(true);
499
500 <<<<<<< GitAnalyzerPlus_ours
501 if (shouldShowIntroScreen()) {
502 showIntroScreen();
503 ||||||| GitAnalyzerPlus_base
504 if (mModel.canMigrateFromOldLauncherDb()) {
505 mLauncherClings.showMigrationCling();
506 } else {
507 mLauncherClings.showFirstRunCling();
508 }
509 }
510
511 protected void onUserLeaveHint() {
512 super.onUserLeaveHint();
513 sPausedFromUserAction = true;
514 }
515
516 /** To be overriden by subclasses to hint to Launcher that we have custom content */
517 protected boolean hasCustomContentToLeft() {
518 return false;
519 }
520
521 /**
522 * To be overridden by subclasses to create the custom content and call
523 * {@link #addToCustomContentPage}. This will only be invoked if
524 =======
525 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
526 // on the device, then we always show the first run cling experience (or if there is no
527 // launcher2). Otherwise, we prompt the user upon started for migration
528 showFirstRunActivity();
529 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
530 if (mModel.canMigrateFromOldLauncherDb(this)) {
531 mLauncherClings.showMigrationCling();
532 } else {
533 mLauncherClings.showFirstRunCling();
534 }
535 >>>>>>> GitAnalyzerPlus_theirs
536 } else {
537 <<<<<<< GitAnalyzerPlus_ours
538 showFirstRunActivity();
539 showFirstRunClings();
540 ||||||| GitAnalyzerPlus_base
541
542 /** To be overriden by subclasses to hint to Launcher that we have custom content */
543 protected boolean hasCustomContentToLeft() {
544 return false;
545 }
546
547 /**
548 * To be overridden by subclasses to create the custom content and call
549 * {@link #addToCustomContentPage}. This will only be invoked if
550 * {@link #hasCustomContentToLeft()} is {@code true}.
551 */
552 protected void addCustomContentToLeft() {
553 =======
554 mLauncherClings.removeFirstRunAndMigrationClings();
555 >>>>>>> GitAnalyzerPlus_theirs
556 }
557 }
558
559 @Override
560 public void onLauncherProviderChange() { }
561
562 /** To be overriden by subclasses to hint to Launcher that we have custom content */
563 protected boolean hasCustomContentToLeft() {
564 return false;
565 }
566
567 /**
568 * To be overridden by subclasses to populate the custom content container and call
569 * {@link #addToCustomContentPage}. This will only be invoked if
570 * {@link #hasCustomContentToLeft()} is {@code true}.
571 */
572 protected void populateCustomContentContainer() {
573 }
574
575 /**
576 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
577 * ensure the custom content page is added or removed if necessary.
578 */
579 protected void invalidateHasCustomContentToLeft() {
580 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
581 // Not bound yet, wait for bindScreens to be called.
582 return;
583 }
584
585 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
586 // Create the custom content page and call the subclass to populate it.
587 mWorkspace.createCustomContentContainer();
588 populateCustomContentContainer();
589 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
590 mWorkspace.removeCustomContentPage();
591 }
592 }
593
594 private void updateGlobalIcons() {
595 boolean searchVisible = false;
596 boolean voiceVisible = false;
597 // If we have a saved version of these external icons, we load them up immediately
598 int coi = getCurrentOrientationIndexForGlobalIcons();
599 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
600 searchVisible = updateGlobalSearchIcon();
601 voiceVisible = updateVoiceSearchIcon(searchVisible);
602 }
603 if (sGlobalSearchIcon[coi] != null) {
604 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
605 searchVisible = true;
606 }
607 if (sVoiceSearchIcon[coi] != null) {
608 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
609 voiceVisible = true;
610 }
611 if (mSearchDropTargetBar != null) {
612 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
613 }
614 }
615
616 private void checkForLocaleChange() {
617 if (sLocaleConfiguration == null) {
618 new AsyncTask<Void, Void, LocaleConfiguration>() {
619 @Override
620 protected LocaleConfiguration doInBackground(Void... unused) {
621 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
622 readConfiguration(Launcher.this, localeConfiguration);
623 return localeConfiguration;
624 }
625
626 @Override
627 protected void onPostExecute(LocaleConfiguration result) {
628 sLocaleConfiguration = result;
629 checkForLocaleChange(); // recursive, but now with a locale configuration
630 }
631 }.execute();
632 return;
633 }
634
635 final Configuration configuration = getResources().getConfiguration();
636
637 final String previousLocale = sLocaleConfiguration.locale;
638 final String locale = configuration.locale.toString();
639
640 final int previousMcc = sLocaleConfiguration.mcc;
641 final int mcc = configuration.mcc;
642
643 final int previousMnc = sLocaleConfiguration.mnc;
644 final int mnc = configuration.mnc;
645
646 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMn🔵
647
648 if (localeChanged) {
649 sLocaleConfiguration.locale = locale;
650 sLocaleConfiguration.mcc = mcc;
651 sLocaleConfiguration.mnc = mnc;
652
653 mIconCache.flush();
654
655 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
656 new AsyncTask<Void, Void, Void>() {
657 public Void doInBackground(Void ... args) {
658 writeConfiguration(Launcher.this, localeConfiguration);
659 return null;
660 }
661 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
662 }
663 }
664
665 private static class LocaleConfiguration {
666 public String locale;
667 public int mcc = -1;
668 public int mnc = -1;
669 }
670
671 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
672 DataInputStream in = null;
673 try {
674 in = new DataInputStream(context.openFileInput(PREFERENCES));
675 configuration.locale = in.readUTF();
676 configuration.mcc = in.readInt();
677 configuration.mnc = in.readInt();
678 } catch (FileNotFoundException e) {
679 // Ignore
680 } catch (IOException e) {
681 // Ignore
682 } finally {
683 if (in != null) {
684 try {
685 in.close();
686 } catch (IOException e) {
687 // Ignore
688 }
689 }
690 }
691 }
692
693 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
694 DataOutputStream out = null;
695 try {
696 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
697 out.writeUTF(configuration.locale);
698 out.writeInt(configuration.mcc);
699 out.writeInt(configuration.mnc);
700 out.flush();
701 } catch (FileNotFoundException e) {
702 // Ignore
703 } catch (IOException e) {
704 //noinspection ResultOfMethodCallIgnored
705 context.getFileStreamPath(PREFERENCES).delete();
706 } finally {
707 if (out != null) {
708 try {
709 out.close();
710 } catch (IOException e) {
711 // Ignore
712 }
713 }
714 }
715 }
716
717 public Stats getStats() {
718 return mStats;
719 }
720
721 public LayoutInflater getInflater() {
722 return mInflater;
723 }
724
725 boolean isDraggingEnabled() {
726 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
727 // that is subsequently removed from the workspace in startBinding().
728 return !mModel.isLoadingWorkspace();
729 }
730
731 static int getScreen() {
732 synchronized (sLock) {
733 return sScreen;
734 }
735 }
736
737 static void setScreen(int screen) {
738 synchronized (sLock) {
739 sScreen = screen;
740 }
741 }
742
743 public static int generateViewId() {
744 if (Build.VERSION.SDK_INT >= 17) {
745 return View.generateViewId();
746 } else {
747 // View.generateViewId() is not available. The following fallback logic is a copy
748 // of its implementation.
749 for (;;) {
750 final int result = sNextGeneratedId.get();
751 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
752 int newValue = result + 1;
753 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
754 if (sNextGeneratedId.compareAndSet(result, newValue)) {
755 return result;
756 }
757 }
758 }
759 }
760
761 public int getViewIdForItem(ItemInfo info) {
762 // This cast is safe given the > 2B range for int.
763 int itemId = (int) info.id;
764 if (mItemIdToViewId.containsKey(itemId)) {
765 return mItemIdToViewId.get(itemId);
766 }
767 int viewId = generateViewId();
768 mItemIdToViewId.put(itemId, viewId);
769 return viewId;
770 }
771
772 /**
773 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
774 * a configuration step, this allows the proper animations to run after other transitions.
775 */
776 private long completeAdd(PendingAddArguments args) {
777 long screenId = args.screenId;
778 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
779 // When the screen id represents an actual screen (as opposed to a rank) we make sure
780 // that the drop page actually exists.
781 screenId = ensurePendingDropLayoutExists(args.screenId);
782 }
783
784 switch (args.requestCode) {
785 case REQUEST_CREATE_SHORTCUT:
786 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
787 args.cellY);
788 break;
789 case REQUEST_CREATE_APPWIDGET:
790 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
791 break;
792 case REQUEST_RECONFIGURE_APPWIDGET:
793 completeRestoreAppWidget(args.appWidgetId);
794 break;
795 }
796 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
797 // if you turned the screen off and then back while in All Apps, Launcher would not
798 // return to the workspace. Clearing mAddInfo.container here fixes this issue
799 resetAddInfo();
800 return screenId;
801 }
802
803 @Override
804 protected void onActivityResult(
805 final int requestCode, final int resultCode, final Intent data) {
806 // Reset the startActivity waiting flag
807 setWaitingForResult(false);
808 final int pendingAddWidgetId = mPendingAddWidgetId;
809 mPendingAddWidgetId = -1;
810
811 Runnable exitSpringLoaded = new Runnable() {
812 @Override
813 public void run() {
814 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
815 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
816 }
817 };
818
819 if (requestCode == REQUEST_BIND_APPWIDGET) {
820 final int appWidgetId = data != null ?
821 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
822 if (resultCode == RESULT_CANCELED) {
823 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
824 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
825 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
826 } else if (resultCode == RESULT_OK) {
827 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
828 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
829 }
830 return;
831 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
832 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
833 mWorkspace.exitOverviewMode(false);
834 }
835 return;
836 }
837
838 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
839 requestCode == REQUEST_CREATE_APPWIDGET);
840
841 final boolean workspaceLocked = isWorkspaceLocked();
842 // We have special handling for widgets
843 if (isWidgetDrop) {
844 final int appWidgetId;
845 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
846 : -1;
847 if (widgetId < 0) {
848 appWidgetId = pendingAddWidgetId;
849 } else {
850 appWidgetId = widgetId;
851 }
852
853 final int result;
854 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
855 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
856 "returned from the widget configuration activity.");
857 result = RESULT_CANCELED;
858 completeTwoStageWidgetDrop(result, appWidgetId);
859 final Runnable onComplete = new Runnable() {
860 @Override
861 public void run() {
862 exitSpringLoadedDragModeDelayed(false, 0, null);
863 }
864 };
865 if (workspaceLocked) {
866 // No need to remove the empty screen if we're mid-binding, as the
867 // the bind will not add the empty screen.
868 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
869 } else {
870 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
871 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
872 }
873 } else {
874 if (!workspaceLocked) {
875 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
876 // When the screen id represents an actual screen (as opposed to a rank)
877 // we make sure that the drop page actually exists.
878 mPendingAddInfo.screenId =
879 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
880 }
881 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
882
883 dropLayout.setDropPending(true);
884 final Runnable onComplete = new Runnable() {
885 @Override
886 public void run() {
887 completeTwoStageWidgetDrop(resultCode, appWidgetId);
888 dropLayout.setDropPending(false);
889 }
890 };
891 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
892 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
893 } else {
894 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
895 mPendingAddInfo);
896 sPendingAddItem = args;
897 }
898 }
899 return;
900 }
901
902 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
903 if (resultCode == RESULT_OK) {
904 // Update the widget view.
905 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
906 pendingAddWidgetId, mPendingAddInfo);
907 if (workspaceLocked) {
908 sPendingAddItem = args;
909 } else {
910 completeAdd(args);
911 }
912 }
913 // Leave the widget in the pending state if the user canceled the configure.
914 return;
915 }
916
917 // The pattern used here is that a user PICKs a specific application,
918 // which, depending on the target, might need to CREATE the actual target.
919
920 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
921 // launch over to the Music app to actually CREATE_SHORTCUT.
922 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
923 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
924 mPendingAddInfo);
925 if (isWorkspaceLocked()) {
926 sPendingAddItem = args;
927 } else {
928 completeAdd(args);
929 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
930 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
931 }
932 } else if (resultCode == RESULT_CANCELED) {
933 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
934 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
935 }
936 mDragLayer.clearAnimatedView();
937 }
938
939 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
940 appWidgetId, ItemInfo info) {
941 PendingAddArguments args = new PendingAddArguments();
942 args.requestCode = requestCode;
943 args.intent = data;
944 args.container = info.container;
945 args.screenId = info.screenId;
946 args.cellX = info.cellX;
947 args.cellY = info.cellY;
948 args.appWidgetId = appWidgetId;
949 return args;
950 }
951
952 /**
953 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
954 *
955 * @param screenId the screen id to check
956 * @return the new screen, or screenId if it exists
957 */
958 private long ensurePendingDropLayoutExists(long screenId) {
959 CellLayout dropLayout =
960 (CellLayout) mWorkspace.getScreenWithId(screenId);
961 if (dropLayout == null) {
962 // it's possible that the add screen was removed because it was
963 // empty and a re-bind occurred
964 mWorkspace.addExtraEmptyScreen();
965 return mWorkspace.commitExtraEmptyScreen();
966 } else {
967 return screenId;
968 }
969 }
970
971 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
972 CellLayout cellLayout =
973 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
974 Runnable onCompleteRunnable = null;
975 int animationType = 0;
976
977 AppWidgetHostView boundWidget = null;
978 if (resultCode == RESULT_OK) {
979 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
980 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
981 mPendingAddWidgetInfo);
982 boundWidget = layout;
983 onCompleteRunnable = new Runnable() {
984 @Override
985 public void run() {
986 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
987 mPendingAddInfo.screenId, layout, null);
988 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
989 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
990 }
991 };
992 } else if (resultCode == RESULT_CANCELED) {
993 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
994 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
995 }
996 if (mDragLayer.getAnimatedView() != null) {
997 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
998 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
999 animationType, boundWidget, true);
1000 } else if (onCompleteRunnable != null) {
1001 // The animated view may be null in the case of a rotation during widget configuration
1002 onCompleteRunnable.run();
1003 }
1004 }
1005
1006 @Override
1007 protected void onStop() {
1008 super.onStop();
1009 FirstFrameAnimatorHelper.setIsVisible(false);
1010 }
1011
1012 @Override
1013 protected void onStart() {
1014 super.onStart();
1015 FirstFrameAnimatorHelper.setIsVisible(true);
1016 }
1017
1018 @Override
1019 protected void onResume() {
1020 long startTime = 0;
1021 if (DEBUG_RESUME_TIME) {
1022 startTime = System.currentTimeMillis();
1023 Log.v(TAG, "Launcher.onResume()");
1024 }
1025 super.onResume();
1026
1027 // Restore the previous launcher state
1028 if (mOnResumeState == State.WORKSPACE) {
1029 showWorkspace(false);
1030 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
1031 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
1032 }
1033 mOnResumeState = State.NONE;
1034
1035 // Background was set to gradient in onPause(), restore to black if in all apps.
1036 setWorkspaceBackground(mState == State.WORKSPACE);
1037
1038 mPaused = false;
1039 if (mRestoring || mOnResumeNeedsLoad) {
1040 setWorkspaceLoading(true);
1041 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
1042 mRestoring = false;
1043 mOnResumeNeedsLoad = false;
1044 }
1045 if (mBindOnResumeCallbacks.size() > 0) {
1046 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1047 // execute them here
1048 long startTimeCallbacks = 0;
1049 if (DEBUG_RESUME_TIME) {
1050 startTimeCallbacks = System.currentTimeMillis();
1051 }
1052
1053 if (mAppsCustomizeContent != null) {
1054 mAppsCustomizeContent.setBulkBind(true);
1055 }
1056 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1057 mBindOnResumeCallbacks.get(i).run();
1058 }
1059 if (mAppsCustomizeContent != null) {
1060 mAppsCustomizeContent.setBulkBind(false);
1061 }
1062 mBindOnResumeCallbacks.clear();
1063 if (DEBUG_RESUME_TIME) {
1064 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1065 (System.currentTimeMillis() - startTimeCallbacks));
1066 }
1067 }
1068 if (mOnResumeCallbacks.size() > 0) {
1069 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1070 mOnResumeCallbacks.get(i).run();
1071 }
1072 mOnResumeCallbacks.clear();
1073 }
1074
1075 // Reset the pressed state of icons that were locked in the press state while activities
1076 // were launching
1077 if (mWaitingForResume != null) {
1078 // Resets the previous workspace icon press state
1079 mWaitingForResume.setStayPressed(false);
1080 }
1081
1082 // It is possible that widgets can receive updates while launcher is not in the foreground.
1083 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1084 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1085 // orientation.
1086 getWorkspace().reinflateWidgetsIfNecessary();
1087
1088 // Process any items that were added while Launcher was away.
1089 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1090
1091 // Update the voice search button proxy
1092 updateVoiceButtonProxyVisible(false);
1093
1094 // Again, as with the above scenario, it's possible that one or more of the global icons
1095 // were updated in the wrong orientation.
1096 updateGlobalIcons();
1097 if (DEBUG_RESUME_TIME) {
1098 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1099 }
1100
1101 if (mWorkspace.getCustomContentCallbacks() != null) {
1102 // If we are resuming and the custom content is the current page, we call onShow().
1103 // It is also poassible that onShow will instead be called slightly after first layout
1104 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1105 if (mWorkspace.isOnOrMovingToCustomContent()) {
1106 mWorkspace.getCustomContentCallbacks().onShow(true);
1107 }
1108 }
1109 mWorkspace.updateInteractionForState();
1110 mWorkspace.onResume();
1111
1112 PackageInstallerCompat.getInstance(this).onResume();
1113 }
1114
1115 @Override
1116 protected void onPause() {
1117 // Ensure that items added to Launcher are queued until Launcher returns
1118 InstallShortcutReceiver.enableInstallQueue();
1119 PackageInstallerCompat.getInstance(this).onPause();
1120
1121 super.onPause();
1122 mPaused = true;
1123 mDragController.cancelDrag();
1124 mDragController.resetLastGestureUpTime();
1125
1126 // We call onHide() aggressively. The custom content callbacks should be able to
1127 // debounce excess onHide calls.
1128 if (mWorkspace.getCustomContentCallbacks() != null) {
1129 mWorkspace.getCustomContentCallbacks().onHide();
1130 }
1131 }
1132
1133 QSBScroller mQsbScroller = new QSBScroller() {
1134 int scrollY = 0;
1135
1136 @Override
1137 public void setScrollY(int scroll) {
1138 scrollY = scroll;
1139
1140 if (mWorkspace.isOnOrMovingToCustomContent()) {
1141 mSearchDropTargetBar.setTranslationY(- scrollY);
1142 getQsbBar().setTranslationY(-scrollY);
1143 }
1144 }
1145 };
1146
1147 public void resetQSBScroll() {
1148 mSearchDropTargetBar.animate().translationY(0).start();
1149 getQsbBar().animate().translationY(0).start();
1150 }
1151
1152 public interface CustomContentCallbacks {
1153 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1154 // by a onResume or by scrolling otherwise.
1155 public void onShow(boolean fromResume);
1156
1157 // Custom content is completely hidden
1158 public void onHide();
1159
1160 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1161 public void onScrollProgressChanged(float progress);
1162
1163 // Indicates whether the user is allowed to scroll away from the custom content.
1164 boolean isScrollingAllowed();
1165 }
1166
1167 protected boolean hasSettings() {
1168 return false;
1169 }
1170
1171 public interface QSBScroller {
1172 public void setScrollY(int scrollY);
1173 }
1174
1175 public QSBScroller addToCustomContentPage(View customContent,
1176 CustomContentCallbacks callbacks, String description) {
1177 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
1178 return mQsbScroller;
1179 }
1180
1181 // The custom content needs to offset its content to account for the QSB
1182 public int getTopOffsetForCustomContent() {
1183 return mWorkspace.getPaddingTop();
1184 }
1185
1186 @Override
1187 public Object onRetainNonConfigurationInstance() {
1188 // Flag the loader to stop early before switching
1189 if (mModel.isCurrentCallbacks(this)) {
1190 mModel.stopLoader();
1191 }
1192 if (mAppsCustomizeContent != null) {
1193 mAppsCustomizeContent.surrender();
1194 }
1195 return Boolean.TRUE;
1196 }
1197
1198 // We can't hide the IME if it was forced open. So don't bother
1199 @Override
1200 public void onWindowFocusChanged(boolean hasFocus) {
1201 super.onWindowFocusChanged(hasFocus);
1202 mHasFocus = hasFocus;
1203 }
1204
1205 private boolean acceptFilter() {
1206 final InputMethodManager inputManager = (InputMethodManager)
1207 getSystemService(Context.INPUT_METHOD_SERVICE);
1208 return !inputManager.isFullscreenMode();
1209 }
1210
1211 @Override
1212 public boolean onKeyDown(int keyCode, KeyEvent event) {
1213 final int uniChar = event.getUnicodeChar();
1214 final boolean handled = super.onKeyDown(keyCode, event);
1215 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1216 if (!handled && acceptFilter() && isKeyNotWhitespace) {
1217 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1218 keyCode, event);
1219 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
1220 // something usable has been typed - start a search
1221 // the typed text will be retrieved and cleared by
1222 // showSearchDialog()
1223 // If there are multiple keystrokes before the search dialog takes focus,
1224 // onSearchRequested() will be called for every keystroke,
1225 // but it is idempotent, so it's fine.
1226 return onSearchRequested();
1227 }
1228 }
1229
1230 // Eat the long press event so the keyboard doesn't come up.
1231 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1232 return true;
1233 }
1234
1235 return handled;
1236 }
1237
1238 private String getTypedText() {
1239 return mDefaultKeySsb.toString();
1240 }
1241
1242 private void clearTypedText() {
1243 mDefaultKeySsb.clear();
1244 mDefaultKeySsb.clearSpans();
1245 Selection.setSelection(mDefaultKeySsb, 0);
1246 }
1247
1248 /**
1249 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1250 * State
1251 */
1252 private static State intToState(int stateOrdinal) {
1253 State state = State.WORKSPACE;
1254 final State[] stateValues = State.values();
1255 for (int i = 0; i < stateValues.length; i++) {
1256 if (stateValues[i].ordinal() == stateOrdinal) {
1257 state = stateValues[i];
1258 break;
1259 }
1260 }
1261 return state;
1262 }
1263
1264 /**
1265 * Restores the previous state, if it exists.
1266 *
1267 * @param savedState The previous state.
1268 */
1269 @SuppressWarnings("unchecked")
1270 private void restoreState(Bundle savedState) {
1271 if (savedState == null) {
1272 return;
1273 }
1274
1275 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
1276 if (state == State.APPS_CUSTOMIZE) {
1277 mOnResumeState = State.APPS_CUSTOMIZE;
1278 }
1279
1280 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1281 PagedView.INVALID_RESTORE_PAGE);
1282 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
1283 mWorkspace.setRestorePage(currentScreen);
1284 }
1285
1286 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
1287 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
1288
1289 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1290 mPendingAddInfo.container = pendingAddContainer;
1291 mPendingAddInfo.screenId = pendingAddScreen;
1292 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1293 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
1294 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1295 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1296 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
1297 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
1298 setWaitingForResult(true);
1299 mRestoring = true;
1300 }
1301
1302 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1303 if (renameFolder) {
1304 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
1305 mFolderInfo = mModel.getFolderById(this, sFolders, id);
1306 mRestoring = true;
1307 }
1308
1309 // Restore the AppsCustomize tab
1310 if (mAppsCustomizeTabHost != null) {
1311 String curTab = savedState.getString("apps_customize_currentTab");
1312 if (curTab != null) {
1313 mAppsCustomizeTabHost.setContentTypeImmediate(
1314 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
1315 mAppsCustomizeContent.loadAssociatedPages(
1316 mAppsCustomizeContent.getCurrentPage());
1317 }
1318
1319 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1320 mAppsCustomizeContent.restorePageForIndex(currentIndex);
1321 }
1322 mItemIdToViewId = (HashMap<Integer, Integer>)
1323 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
1324 }
1325
1326 /**
1327 * Finds all the views we need and configure them properly.
1328 */
1329 private void setupViews() {
1330 final DragController dragController = mDragController;
1331
1332 mLauncherView = findViewById(R.id.launcher);
1333 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
1334 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1335 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
1336 mWorkspace.setPageSwitchListener(this);
1337 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
1338
1339 mLauncherView.setSystemUiVisibility(
1340 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1341 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
1342
1343 // Setup the drag layer
1344 mDragLayer.setup(this, dragController);
1345
1346 // Setup the hotseat
1347 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1348 if (mHotseat != null) {
1349 mHotseat.setup(this);
1350 mHotseat.setOnLongClickListener(this);
1351 }
1352
1353 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1354 View widgetButton = findViewById(R.id.widget_button);
1355 widgetButton.setOnClickListener(new OnClickListener() {
1356 @Override
1357 public void onClick(View arg0) {
1358 if (!mWorkspace.isSwitchingState()) {
1359 onClickAddWidgetButton(arg0);
1360 }
1361 }
1362 });
1363 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1364
1365 View wallpaperButton = findViewById(R.id.wallpaper_button);
1366 wallpaperButton.setOnClickListener(new OnClickListener() {
1367 @Override
1368 public void onClick(View arg0) {
1369 if (!mWorkspace.isSwitchingState()) {
1370 onClickWallpaperPicker(arg0);
1371 }
1372 }
1373 });
1374 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1375
1376 View settingsButton = findViewById(R.id.settings_button);
1377 if (hasSettings()) {
1378 settingsButton.setOnClickListener(new OnClickListener() {
1379 @Override
1380 public void onClick(View arg0) {
1381 if (!mWorkspace.isSwitchingState()) {
1382 onClickSettingsButton(arg0);
1383 }
1384 }
1385 });
1386 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1387 } else {
1388 settingsButton.setVisibility(View.GONE);
1389 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1390 lp.gravity = Gravity.END | Gravity.TOP;
1391 widgetButton.requestLayout();
1392 }
1393
1394 mOverviewPanel.setAlpha(0f);
1395
1396 // Setup the workspace
1397 mWorkspace.setHapticFeedbackEnabled(false);
1398 mWorkspace.setOnLongClickListener(this);
1399 mWorkspace.setup(dragController);
1400 dragController.addDragListener(mWorkspace);
1401
1402 // Get the search/delete bar
1403 mSearchDropTargetBar = (SearchDropTargetBar)
1404 mDragLayer.findViewById(R.id.search_drop_target_bar);
1405
1406 // Setup AppsCustomize
1407 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
1408 mAppsCustomizeContent = (AppsCustomizePagedView)
1409 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1410 mAppsCustomizeContent.setup(this, dragController);
1411
1412 // Setup the drag controller (drop targets have to be added in reverse order in priority)
1413 dragController.setDragScoller(mWorkspace);
1414 dragController.setScrollView(mDragLayer);
1415 dragController.setMoveTarget(mWorkspace);
1416 dragController.addDropTarget(mWorkspace);
1417 if (mSearchDropTargetBar != null) {
1418 mSearchDropTargetBar.setup(this, dragController);
1419 }
1420
1421 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
1422 Log.v(TAG, "adding WeightWatcher");
1423 mWeightWatcher = new WeightWatcher(this);
1424 mWeightWatcher.setAlpha(0.5f);
1425 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
1426 new FrameLayout.LayoutParams(
1427 FrameLayout.LayoutParams.MATCH_PARENT,
1428 FrameLayout.LayoutParams.WRAP_CONTENT,
1429 Gravity.BOTTOM)
1430 );
1431
1432 boolean show = shouldShowWeightWatcher();
1433 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
1434 }
1435 }
1436
1437 /**
1438 * Sets the all apps button. This method is called from {@link Hotseat}.
1439 */
1440 public void setAllAppsButton(View allAppsButton) {
1441 mAllAppsButton = allAppsButton;
1442 }
1443
1444 public View getAllAppsButton() {
1445 return mAllAppsButton;
1446 }
1447
1448 /**
1449 * Creates a view representing a shortcut.
1450 *
1451 * @param info The data structure describing the shortcut.
1452 *
1453 * @return A View inflated from R.layout.application.
1454 */
1455 View createShortcut(ShortcutInfo info) {
1456 return createShortcut(R.layout.application,
1457 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
1458 }
1459
1460 /**
1461 * Creates a view representing a shortcut inflated from the specified resource.
1462 *
1463 * @param layoutResId The id of the XML layout used to create the shortcut.
1464 * @param parent The group the shortcut belongs to.
1465 * @param info The data structure describing the shortcut.
1466 *
1467 * @return A View inflated from layoutResId.
1468 */
1469 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
1470 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1471 favorite.applyFromShortcutInfo(info, mIconCache, true);
1472 favorite.setOnClickListener(this);
1473 favorite.setOnFocusChangeListener(mFocusHandler);
1474 return favorite;
1475 }
1476
1477 /**
1478 * Add a shortcut to the workspace.
1479 *
1480 * @param data The intent describing the shortcut.
1481 * @param cellInfo The position on screen where to create the shortcut.
1482 */
1483 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
1484 int cellY) {
1485 int[] cellXY = mTmpAddItemCellCoordinates;
1486 int[] touchXY = mPendingAddInfo.dropPos;
1487 CellLayout layout = getCellLayout(container, screenId);
1488
1489 boolean foundCellSpan = false;
1490
1491 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
1492 if (info == null) {
1493 return;
1494 }
1495 final View view = createShortcut(info);
1496
1497 // First we check if we already know the exact location where we want to add this item.
1498 if (cellX >= 0 && cellY >= 0) {
1499 cellXY[0] = cellX;
1500 cellXY[1] = cellY;
1501 foundCellSpan = true;
1502
1503 // If appropriate, either create a folder or add to an existing folder
1504 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
1505 true, null,null)) {
1506 return;
1507 }
1508 DragObject dragObject = new DragObject();
1509 dragObject.dragInfo = info;
1510 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1511 true)) {
1512 return;
1513 }
1514 } else if (touchXY != null) {
1515 // when dragging and dropping, just find the closest free spot
1516 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
1517 foundCellSpan = (result != null);
1518 } else {
1519 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1520 }
1521
1522 if (!foundCellSpan) {
1523 showOutOfSpaceMessage(isHotseatLayout(layout));
1524 return;
1525 }
1526
1527 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
1528
1529 if (!mRestoring) {
1530 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
1531 isWorkspaceLocked());
1532 }
1533 }
1534
1535 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1536 int minHeight) {
1537 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
1538 // We want to account for the extra amount of padding that we are adding to the widget
1539 // to ensure that it gets the full amount of space that it has requested
1540 int requiredWidth = minWidth + padding.left + padding.right;
1541 int requiredHeight = minHeight + padding.top + padding.bottom;
1542 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
1543 }
1544
1545 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1546 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
1547 }
1548
1549 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1550 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
1551 }
1552
1553 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1554 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
1555 }
1556
1557 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1558 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
1559 info.minResizeHeight);
1560 }
1561
1562 /**
1563 * Add a widget to the workspace.
1564 *
1565 * @param appWidgetId The app widget id
1566 * @param cellInfo The position on screen where to create the widget.
1567 */
1568 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
1569 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1570 if (appWidgetInfo == null) {
1571 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1572 }
1573
1574 // Calculate the grid spans needed to fit this widget
1575 CellLayout layout = getCellLayout(container, screenId);
1576
1577 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1578 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
1579
1580 // Try finding open space on Launcher screen
1581 // We have saved the position to which the widget was dragged-- this really only matters
1582 // if we are placing widgets on a "spring-loaded" screen
1583 int[] cellXY = mTmpAddItemCellCoordinates;
1584 int[] touchXY = mPendingAddInfo.dropPos;
1585 int[] finalSpan = new int[2];
1586 boolean foundCellSpan = false;
1587 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1588 cellXY[0] = mPendingAddInfo.cellX;
1589 cellXY[1] = mPendingAddInfo.cellY;
1590 spanXY[0] = mPendingAddInfo.spanX;
1591 spanXY[1] = mPendingAddInfo.spanY;
1592 foundCellSpan = true;
1593 } else if (touchXY != null) {
1594 // when dragging and dropping, just find the closest free spot
1595 int[] result = layout.findNearestVacantArea(
1596 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1597 spanXY[1], cellXY, finalSpan);
1598 spanXY[0] = finalSpan[0];
1599 spanXY[1] = finalSpan[1];
1600 foundCellSpan = (result != null);
1601 } else {
1602 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
1603 }
1604
1605 if (!foundCellSpan) {
1606 if (appWidgetId != -1) {
1607 // Deleting an app widget ID is a void call but writes to disk before returning
1608 // to the caller...
1609 new AsyncTask<Void, Void, Void>() {
1610 public Void doInBackground(Void ... args) {
1611 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1612 return null;
1613 }
1614 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
1615 }
1616 showOutOfSpaceMessage(isHotseatLayout(layout));
1617 return;
1618 }
1619
1620 // Build Launcher-specific widget info and save to database
1621 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1622 appWidgetInfo.provider);
1623 launcherInfo.spanX = spanXY[0];
1624 launcherInfo.spanY = spanXY[1];
1625 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1626 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
1627 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
1628
1629 LauncherModel.addItemToDatabase(this, launcherInfo,
1630 container, screenId, cellXY[0], cellXY[1], false);
1631
1632 if (!mRestoring) {
1633 if (hostView == null) {
1634 // Perform actual inflation because we're live
1635 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1636 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1637 } else {
1638 // The AppWidgetHostView has already been inflated and instantiated
1639 launcherInfo.hostView = hostView;
1640 }
1641
1642 launcherInfo.hostView.setTag(launcherInfo);
1643 launcherInfo.hostView.setVisibility(View.VISIBLE);
1644 launcherInfo.notifyWidgetSizeChanged(this);
1645
1646 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
1647 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
1648
1649 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
1650 }
1651 resetAddInfo();
1652 }
1653
1654 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1655 @Override
1656 public void onReceive(Context context, Intent intent) {
1657 final String action = intent.getAction();
1658 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1659 mUserPresent = false;
1660 mDragLayer.clearAllResizeFrames();
1661 updateRunning();
1662
1663 // Reset AllApps to its initial state only if we are not in the middle of
1664 // processing a multi-step drop
1665 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1666 showWorkspace(false);
1667 }
1668 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1669 mUserPresent = true;
1670 updateRunning();
1671 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1672 mModel.resetLoadedState(false, true);
1673 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1674 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1675 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1676 mModel.resetLoadedState(false, true);
1677 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1678 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1679 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
1680 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1681 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1682 getModel().forceReload();
1683 }
1684 }
1685 };
1686
1687 @Override
1688 public void onAttachedToWindow() {
1689 super.onAttachedToWindow();
1690
1691 // Listen for broadcasts related to user-presence
1692 final IntentFilter filter = new IntentFilter();
1693 filter.addAction(Intent.ACTION_SCREEN_OFF);
1694 filter.addAction(Intent.ACTION_USER_PRESENT);
1695 // For handling managed profiles
1696 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1697 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
1698 if (ENABLE_DEBUG_INTENTS) {
1699 filter.addAction(DebugIntents.DELETE_DATABASE);
1700 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1701 }
1702 registerReceiver(mReceiver, filter);
1703 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
1704 setupTransparentSystemBarsForLmp();
1705 mAttached = true;
1706 mVisible = true;
1707 }
1708
1709 /**
1710 * Sets up transparent navigation and status bars in LMP.
1711 * This method is a no-op for other platform versions.
1712 */
1713 @TargetApi(19)
1714 private void setupTransparentSystemBarsForLmp() {
1715 // TODO(sansid): use the APIs directly when compiling against L sdk.
1716 // Currently we use reflection to access the flags and the API to set the transparency
1717 // on the System bars.
1718 if (Utilities.isLmpOrAbove()) {
1719 try {
1720 getWindow().getAttributes().systemUiVisibility |=
1721 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1722 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1723 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1724 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1725 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1726 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1727 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1728 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1729
1730 Method setStatusBarColorMethod =
1731 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1732 Method setNavigationBarColorMethod =
1733 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1734 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1735 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1736 } catch (NoSuchFieldException e) {
1737 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1738 } catch (NoSuchMethodException ex) {
1739 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1740 } catch (IllegalAccessException e) {
1741 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1742 } catch (IllegalArgumentException e) {
1743 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1744 } catch (InvocationTargetException e) {
1745 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1746 } finally {}
1747 }
1748 }
1749
1750 @Override
1751 public void onDetachedFromWindow() {
1752 super.onDetachedFromWindow();
1753 mVisible = false;
1754
1755 if (mAttached) {
1756 unregisterReceiver(mReceiver);
1757 mAttached = false;
1758 }
1759 updateRunning();
1760 }
1761
1762 public void onWindowVisibilityChanged(int visibility) {
1763 mVisible = visibility == View.VISIBLE;
1764 updateRunning();
1765 // The following code used to be in onResume, but it turns out onResume is called when
1766 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1767 // is a more appropriate event to handle
1768 if (mVisible) {
1769 mAppsCustomizeTabHost.onWindowVisible();
1770 if (!mWorkspaceLoading) {
1771 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
1772 // We want to let Launcher draw itself at least once before we force it to build
1773 // layers on all the workspace pages, so that transitioning to Launcher from other
1774 // apps is nice and speedy.
1775 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
1776 private boolean mStarted = false;
1777 public void onDraw() {
1778 if (mStarted) return;
1779 mStarted = true;
1780 // We delay the layer building a bit in order to give
1781 // other message processing a time to run. In particular
1782 // this avoids a delay in hiding the IME if it was
1783 // currently shown, because doing that may involve
1784 // some communication back with the app.
1785 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
1786 final ViewTreeObserver.OnDrawListener listener = this;
1787 mWorkspace.post(new Runnable() {
1788 public void run() {
1789 if (mWorkspace != null &&
1790 mWorkspace.getViewTreeObserver() != null) {
1791 mWorkspace.getViewTreeObserver().
1792 removeOnDrawListener(listener);
1793 }
1794 }
1795 });
1796 return;
1797 }
1798 });
1799 }
1800 clearTypedText();
1801 }
1802 }
1803
1804 private void sendAdvanceMessage(long delay) {
1805 mHandler.removeMessages(ADVANCE_MSG);
1806 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1807 mHandler.sendMessageDelayed(msg, delay);
1808 mAutoAdvanceSentTime = System.currentTimeMillis();
1809 }
1810
1811 private void updateRunning() {
1812 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1813 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1814 mAutoAdvanceRunning = autoAdvanceRunning;
1815 if (autoAdvanceRunning) {
1816 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1817 sendAdvanceMessage(delay);
1818 } else {
1819 if (!mWidgetsToAdvance.isEmpty()) {
1820 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1821 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1822 }
1823 mHandler.removeMessages(ADVANCE_MSG);
1824 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
1825 }
1826 }
1827 }
1828
1829 private final Handler mHandler = new Handler() {
1830 @Override
1831 public void handleMessage(Message msg) {
1832 if (msg.what == ADVANCE_MSG) {
1833 int i = 0;
1834 for (View key: mWidgetsToAdvance.keySet()) {
1835 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1836 final int delay = mAdvanceStagger * i;
1837 if (v instanceof Advanceable) {
1838 postDelayed(new Runnable() {
1839 public void run() {
1840 ((Advanceable) v).advance();
1841 }
1842 }, delay);
1843 }
1844 i++;
1845 }
1846 sendAdvanceMessage(mAdvanceInterval);
1847 }
1848 }
1849 };
1850
1851 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1852 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
1853 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1854 if (v instanceof Advanceable) {
1855 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1856 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
1857 updateRunning();
1858 }
1859 }
1860
1861 void removeWidgetToAutoAdvance(View hostView) {
1862 if (mWidgetsToAdvance.containsKey(hostView)) {
1863 mWidgetsToAdvance.remove(hostView);
1864 updateRunning();
1865 }
1866 }
1867
1868 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1869 removeWidgetToAutoAdvance(launcherInfo.hostView);
1870 launcherInfo.hostView = null;
1871 }
1872
1873 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1874 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1875 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
1876 }
1877
1878 public DragLayer getDragLayer() {
1879 return mDragLayer;
1880 }
1881
1882 public Workspace getWorkspace() {
1883 return mWorkspace;
1884 }
1885
1886 public Hotseat getHotseat() {
1887 return mHotseat;
1888 }
1889
1890 public ViewGroup getOverviewPanel() {
1891 return mOverviewPanel;
1892 }
1893
1894 public SearchDropTargetBar getSearchBar() {
1895 return mSearchDropTargetBar;
1896 }
1897
1898 public LauncherAppWidgetHost getAppWidgetHost() {
1899 return mAppWidgetHost;
1900 }
1901
1902 public LauncherModel getModel() {
1903 return mModel;
1904 }
1905
1906 protected SharedPreferences getSharedPrefs() {
1907 return mSharedPrefs;
1908 }
1909
1910 public void closeSystemDialogs() {
1911 getWindow().closeAllPanels();
1912
1913 // Whatever we were doing is hereby canceled.
1914 setWaitingForResult(false);
1915 }
1916
1917 @Override
1918 protected void onNewIntent(Intent intent) {
1919 long startTime = 0;
1920 if (DEBUG_RESUME_TIME) {
1921 startTime = System.currentTimeMillis();
1922 }
1923 super.onNewIntent(intent);
1924
1925 // Close the menu
1926 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
1927 // also will cancel mWaitingForResult.
1928 closeSystemDialogs();
1929
1930 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1931 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1932 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1933
1934 if (mWorkspace == null) {
1935 // Can be cases where mWorkspace is null, this prevents a NPE
1936 return;
1937 }
1938 Folder openFolder = mWorkspace.getOpenFolder();
1939 // In all these cases, only animate if we're already on home
1940 mWorkspace.exitWidgetResizeMode();
1941 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1942 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
1943 mWorkspace.moveToDefaultScreen(true);
1944 }
1945
1946 closeFolder();
1947 exitSpringLoadedDragMode();
1948
1949 // If we are already on home, then just animate back to the workspace,
1950 // otherwise, just wait until onResume to set the state back to Workspace
1951 if (alreadyOnHome) {
1952 showWorkspace(true);
1953 } else {
1954 mOnResumeState = State.WORKSPACE;
1955 }
1956
1957 final View v = getWindow().peekDecorView();
1958 if (v != null && v.getWindowToken() != null) {
1959 InputMethodManager imm = (InputMethodManager)getSystemService(
1960 INPUT_METHOD_SERVICE);
1961 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1962 }
1963
1964 // Reset the apps customize page
1965 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1966 mAppsCustomizeTabHost.reset();
1967 }
1968
1969 onHomeIntent();
1970 }
1971
1972 if (DEBUG_RESUME_TIME) {
1973 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1974 }
1975 }
1976
1977 /**
1978 * Override point for subclasses to prevent movement to the default screen when the home
1979 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1980 */
1981 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1982 return true;
1983 }
1984
1985 /**
1986 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
1987 */
1988 protected void onHomeIntent() {
1989 // Do nothing
1990 }
1991
1992 @Override
1993 public void onRestoreInstanceState(Bundle state) {
1994 super.onRestoreInstanceState(state);
1995 for (int page: mSynchronouslyBoundPages) {
1996 mWorkspace.restoreInstanceStateForChild(page);
1997 }
1998 }
1999
2000 @Override
2001 protected void onSaveInstanceState(Bundle outState) {
2002 if (mWorkspace.getChildCount() > 0) {
2003 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
2004 mWorkspace.getCurrentPageOffsetFromCustomContent());
2005 }
2006 super.onSaveInstanceState(outState);
2007
2008 outState.putInt(RUNTIME_STATE, mState.ordinal());
2009 // We close any open folder since it will not be re-opened, and we need to make sure
2010 // this state is reflected.
2011 closeFolder();
2012
2013 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
2014 mWaitingForResult) {
2015 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
2016 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
2017 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2018 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
2019 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2020 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2021 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
2022 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
2023 }
2024
2025 if (mFolderInfo != null && mWaitingForResult) {
2026 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2027 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2028 }
2029
2030 // Save the current AppsCustomize tab
2031 if (mAppsCustomizeTabHost != null) {
2032 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2033 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
2034 if (currentTabTag != null) {
2035 outState.putString("apps_customize_currentTab", currentTabTag);
2036 }
2037 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2038 outState.putInt("apps_customize_currentIndex", currentIndex);
2039 }
2040 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
2041 }
2042
2043 @Override
2044 public void onDestroy() {
2045 super.onDestroy();
2046
2047 // Remove all pending runnables
2048 mHandler.removeMessages(ADVANCE_MSG);
2049 mHandler.removeMessages(0);
2050 mWorkspace.removeCallbacks(mBuildLayersRunnable);
2051
2052 // Stop callbacks from LauncherModel
2053 LauncherAppState app = (LauncherAppState.getInstance());
2054
2055 // It's possible to receive onDestroy after a new Launcher activity has
2056 // been created. In this case, don't interfere with the new Launcher.
2057 if (mModel.isCurrentCallbacks(this)) {
2058 mModel.stopLoader();
2059 app.setLauncher(null);
2060 }
2061
2062 try {
2063 mAppWidgetHost.stopListening();
2064 } catch (NullPointerException ex) {
2065 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
2066 }
2067 mAppWidgetHost = null;
2068
2069 mWidgetsToAdvance.clear();
2070
2071 TextKeyListener.getInstance().release();
2072
2073 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2074 // to prevent leaking Launcher activities on orientation change.
2075 if (mModel != null) {
2076 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2077 }
2078
2079 getContentResolver().unregisterContentObserver(mWidgetObserver);
2080 unregisterReceiver(mCloseSystemDialogsReceiver);
2081
2082 mDragLayer.clearAllResizeFrames();
2083 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
2084 mWorkspace.removeAllWorkspaceScreens();
2085 mWorkspace = null;
2086 mDragController = null;
2087
2088 PackageInstallerCompat.getInstance(this).onStop();
2089 LauncherAnimUtils.onDestroyActivity();
2090 }
2091
2092 public DragController getDragController() {
2093 return mDragController;
2094 }
2095
2096 @Override
2097 public void startActivityForResult(Intent intent, int requestCode) {
2098 if (requestCode >= 0) {
2099 setWaitingForResult(true);
2100 }
2101 super.startActivityForResult(intent, requestCode);
2102 }
2103
2104 /**
2105 * Indicates that we want global search for this activity by setting the globalSearch
2106 * argument for {@link #startSearch} to true.
2107 */
2108 @Override
2109 public void startSearch(String initialQuery, boolean selectInitialQuery,
2110 Bundle appSearchData, boolean globalSearch) {
2111
2112 showWorkspace(true);
2113
2114 if (initialQuery == null) {
2115 // Use any text typed in the launcher as the initial query
2116 initialQuery = getTypedText();
2117 }
2118 if (appSearchData == null) {
2119 appSearchData = new Bundle();
2120 appSearchData.putString("source", "launcher-search");
2121 }
2122 Rect sourceBounds = new Rect();
2123 if (mSearchDropTargetBar != null) {
2124 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2125 }
2126
2127 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
2128 appSearchData, sourceBounds);
2129 if (clearTextImmediately) {
2130 clearTypedText();
2131 }
2132 }
2133
2134 /**
2135 * Start a text search.
2136 *
2137 * @return {@code true} if the search will start immediately, so any further keypresses
2138 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2139 * to buffer keypresses.
2140 */
2141 public boolean startSearch(String initialQuery,
2142 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2143 startGlobalSearch(initialQuery, selectInitialQuery,
2144 appSearchData, sourceBounds);
2145 return false;
2146 }
2147
2148 /**
2149 * Starts the global search activity. This code is a copied from SearchManager
2150 */
2151 private void startGlobalSearch(String initialQuery,
2152 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2153 final SearchManager searchManager =
2154 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2155 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2156 if (globalSearchActivity == null) {
2157 Log.w(TAG, "No global search activity found.");
2158 return;
2159 }
2160 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2161 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2162 intent.setComponent(globalSearchActivity);
2163 // Make sure that we have a Bundle to put source in
2164 if (appSearchData == null) {
2165 appSearchData = new Bundle();
2166 } else {
2167 appSearchData = new Bundle(appSearchData);
2168 }
2169 // Set source to package name of app that starts global search, if not set already.
2170 if (!appSearchData.containsKey("source")) {
2171 appSearchData.putString("source", getPackageName());
2172 }
2173 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2174 if (!TextUtils.isEmpty(initialQuery)) {
2175 intent.putExtra(SearchManager.QUERY, initialQuery);
2176 }
2177 if (selectInitialQuery) {
2178 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2179 }
2180 intent.setSourceBounds(sourceBounds);
2181 try {
2182 startActivity(intent);
2183 } catch (ActivityNotFoundException ex) {
2184 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2185 }
2186 }
2187
2188 public boolean isOnCustomContent() {
2189 return mWorkspace.isOnOrMovingToCustomContent();
2190 }
2191
2192 @Override
2193 public boolean onPrepareOptionsMenu(Menu menu) {
2194 super.onPrepareOptionsMenu(menu);
2195 if (!isOnCustomContent()) {
2196 // Close any open folders
2197 closeFolder();
2198 // Stop resizing any widgets
2199 mWorkspace.exitWidgetResizeMode();
2200 if (!mWorkspace.isInOverviewMode()) {
2201 // Show the overview mode
2202 showOverviewMode(true);
2203 } else {
2204 showWorkspace(true);
2205 }
2206 }
2207 return false;
2208 }
2209
2210 @Override
2211 public boolean onSearchRequested() {
2212 startSearch(null, false, null, true);
2213 // Use a custom animation for launching search
2214 return true;
2215 }
2216
2217 public boolean isWorkspaceLocked() {
2218 return mWorkspaceLoading || mWaitingForResult;
2219 }
2220
2221 public boolean isWorkspaceLoading() {
2222 return mWorkspaceLoading;
2223 }
2224
2225 private void setWorkspaceLoading(boolean value) {
2226 boolean isLocked = isWorkspaceLocked();
2227 mWorkspaceLoading = value;
2228 if (isLocked != isWorkspaceLocked()) {
2229 onWorkspaceLockedChanged();
2230 }
2231 }
2232
2233 private void setWaitingForResult(boolean value) {
2234 boolean isLocked = isWorkspaceLocked();
2235 mWaitingForResult = value;
2236 if (isLocked != isWorkspaceLocked()) {
2237 onWorkspaceLockedChanged();
2238 }
2239 }
2240
2241 protected void onWorkspaceLockedChanged() { }
2242
2243 private void resetAddInfo() {
2244 mPendingAddInfo.container = ItemInfo.NO_ID;
2245 mPendingAddInfo.screenId = -1;
2246 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2247 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
2248 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
2249 mPendingAddInfo.dropPos = null;
2250 }
2251
2252 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2253 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2254 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2255 }
2256
2257 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2258 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2259 delay) {
2260 if (appWidgetInfo.configure != null) {
2261 mPendingAddWidgetInfo = appWidgetInfo;
2262 mPendingAddWidgetId = appWidgetId;
2263
2264 // Launch over to configure widget, if needed
2265 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2266 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2267
2268 } else {
2269 // Otherwise just add it
2270 Runnable onComplete = new Runnable() {
2271 @Override
2272 public void run() {
2273 // Exit spring loaded mode if necessary after adding the widget
2274 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2275 null);
2276 }
2277 };
2278 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
2279 appWidgetInfo);
2280 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
2281 }
2282 }
2283
2284 protected void moveToCustomContentScreen(boolean animate) {
2285 // Close any folders that may be open.
2286 closeFolder();
2287 mWorkspace.moveToCustomContentScreen(animate);
2288 }
2289 /**
2290 * Process a shortcut drop.
2291 *
2292 * @param componentName The name of the component
2293 * @param screenId The ID of the screen where it should be added
2294 * @param cell The cell it should be added to, optional
2295 * @param position The location on the screen where it was dropped, optional
2296 */
2297 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2298 int[] cell, int[] loc) {
2299 resetAddInfo();
2300 mPendingAddInfo.container = container;
2301 mPendingAddInfo.screenId = screenId;
2302 mPendingAddInfo.dropPos = loc;
2303
2304 if (cell != null) {
2305 mPendingAddInfo.cellX = cell[0];
2306 mPendingAddInfo.cellY = cell[1];
2307 }
2308
2309 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2310 createShortcutIntent.setComponent(componentName);
2311 processShortcut(createShortcutIntent);
2312 }
2313
2314 /**
2315 * Process a widget drop.
2316 *
2317 * @param info The PendingAppWidgetInfo of the widget being added.
2318 * @param screenId The ID of the screen where it should be added
2319 * @param cell The cell it should be added to, optional
2320 * @param position The location on the screen where it was dropped, optional
2321 */
2322 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2323 int[] cell, int[] span, int[] loc) {
2324 resetAddInfo();
2325 mPendingAddInfo.container = info.container = container;
2326 mPendingAddInfo.screenId = info.screenId = screenId;
2327 mPendingAddInfo.dropPos = loc;
2328 mPendingAddInfo.minSpanX = info.minSpanX;
2329 mPendingAddInfo.minSpanY = info.minSpanY;
2330
2331 if (cell != null) {
2332 mPendingAddInfo.cellX = cell[0];
2333 mPendingAddInfo.cellY = cell[1];
2334 }
2335 if (span != null) {
2336 mPendingAddInfo.spanX = span[0];
2337 mPendingAddInfo.spanY = span[1];
2338 }
2339
2340 AppWidgetHostView hostView = info.boundWidget;
2341 int appWidgetId;
2342 if (hostView != null) {
2343 appWidgetId = hostView.getAppWidgetId();
2344 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
2345 } else {
2346 // In this case, we either need to start an activity to get permission to bind
2347 // the widget, or we need to start an activity to configure the widget, or both.
2348 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
2349 Bundle options = info.bindOptions;
2350
2351 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2352 appWidgetId, info.info, options);
2353 if (success) {
2354 addAppWidgetImpl(appWidgetId, info, null, info.info);
2355 } else {
2356 mPendingAddWidgetInfo = info.info;
2357 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2358 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2359 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
2360 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2361 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
2362 // TODO: we need to make sure that this accounts for the options bundle.
2363 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
2364 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2365 }
2366 }
2367 }
2368
2369 void processShortcut(Intent intent) {
2370 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
2371 }
2372
2373 void processWallpaper(Intent intent) {
2374 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2375 }
2376
2377 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
2378 int cellY) {
2379 final FolderInfo folderInfo = new FolderInfo();
2380 folderInfo.title = getText(R.string.folder_name);
2381
2382 // Update the model
2383 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
2384 false);
2385 sFolders.put(folderInfo.id, folderInfo);
2386
2387 // Create the view
2388 FolderIcon newFolder =
2389 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
2390 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
2391 isWorkspaceLocked());
2392 // Force measure the new folder icon
2393 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2394 parent.getShortcutsAndWidgets().measureChild(newFolder);
2395 return newFolder;
2396 }
2397
2398 void removeFolder(FolderInfo folder) {
2399 sFolders.remove(folder.id);
2400 }
2401
2402 protected ComponentName getWallpaperPickerComponent() {
2403 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
2404 }
2405
2406 /**
2407 * Registers various content observers. The current implementation registers
2408 * only a favorites observer to keep track of the favorites applications.
2409 */
2410 private void registerContentObservers() {
2411 ContentResolver resolver = getContentResolver();
2412 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2413 true, mWidgetObserver);
2414 }
2415
2416 @Override
2417 public boolean dispatchKeyEvent(KeyEvent event) {
2418 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2419 switch (event.getKeyCode()) {
2420 case KeyEvent.KEYCODE_HOME:
2421 return true;
2422 case KeyEvent.KEYCODE_VOLUME_DOWN:
2423 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
2424 dumpState();
2425 return true;
2426 }
2427 break;
2428 }
2429 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2430 switch (event.getKeyCode()) {
2431 case KeyEvent.KEYCODE_HOME:
2432 return true;
2433 }
2434 }
2435
2436 return super.dispatchKeyEvent(event);
2437 }
2438
2439 @Override
2440 public void onBackPressed() {
2441 if (isAllAppsVisible()) {
2442 if (mAppsCustomizeContent.getContentType() ==
2443 AppsCustomizePagedView.ContentType.Applications) {
2444 showWorkspace(true);
2445 } else {
2446 showOverviewMode(true);
2447 }
2448 } else if (mWorkspace.isInOverviewMode()) {
2449 mWorkspace.exitOverviewMode(true);
2450 } else if (mWorkspace.getOpenFolder() != null) {
2451 Folder openFolder = mWorkspace.getOpenFolder();
2452 if (openFolder.isEditingName()) {
2453 openFolder.dismissEditingName();
2454 } else {
2455 closeFolder();
2456 }
2457 } else {
2458 mWorkspace.exitWidgetResizeMode();
2459
2460 // Back button is a no-op here, but give at least some feedback for the button press
2461 mWorkspace.showOutlinesTemporarily();
2462 }
2463 }
2464
2465 /**
2466 * Re-listen when widgets are reset.
2467 */
2468 private void onAppWidgetReset() {
2469 if (mAppWidgetHost != null) {
2470 mAppWidgetHost.startListening();
2471 }
2472 }
2473
2474 /**
2475 * Launches the intent referred by the clicked shortcut.
2476 *
2477 * @param v The view representing the clicked shortcut.
2478 */
2479 public void onClick(View v) {
2480 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2481 // view has detached (it's possible for this to happen if the view is removed mid touch).
2482 if (v.getWindowToken() == null) {
2483 return;
2484 }
2485
2486 if (!mWorkspace.isFinishedSwitchingState()) {
2487 return;
2488 }
2489
2490 if (v instanceof Workspace) {
2491 if (mWorkspace.isInOverviewMode()) {
2492 mWorkspace.exitOverviewMode(true);
2493 }
2494 return;
2495 }
2496
2497 if (v instanceof CellLayout) {
2498 if (mWorkspace.isInOverviewMode()) {
2499 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
2500 }
2501 }
2502
2503 Object tag = v.getTag();
2504 if (tag instanceof ShortcutInfo) {
2505 onClickAppShortcut(v);
2506 } else if (tag instanceof FolderInfo) {
2507 if (v instanceof FolderIcon) {
2508 onClickFolderIcon(v);
2509 }
2510 } else if (v == mAllAppsButton) {
2511 onClickAllAppsButton(v);
2512 } else if (tag instanceof AppInfo) {
2513 startAppShortcutOrInfoActivity(v);
2514 } else if (tag instanceof LauncherAppWidgetInfo) {
2515 if (v instanceof PendingAppWidgetHostView) {
2516 onClickPendingWidget((PendingAppWidgetHostView) v);
2517 }
2518 }
2519 }
2520
2521 public void onClickPagedViewIcon(View v) {
2522 startAppShortcutOrInfoActivity(v);
2523 }
2524
2525 public boolean onTouch(View v, MotionEvent event) {
2526 return false;
2527 }
2528
2529 /**
2530 * Event handler for the app widget view which has not fully restored.
2531 */
2532 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2533 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2534 if (v.isReadyForClickSetup()) {
2535 int widgetId = info.appWidgetId;
2536 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2537 if (appWidgetInfo != null) {
2538 mPendingAddWidgetInfo = appWidgetInfo;
2539 mPendingAddInfo.copyFrom(info);
2540 mPendingAddWidgetId = widgetId;
2541
2542 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2543 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
2544 }
2545 } else if (info.installProgress < 0) {
2546 // The install has not been queued
2547 final String packageName = info.providerName.getPackageName();
2548 showBrokenAppInstallDialog(packageName,
2549 new DialogInterface.OnClickListener() {
2550 public void onClick(DialogInterface dialog, int id) {
2551 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2552 }
2553 });
2554 } else {
2555 // Download has started.
2556 final String packageName = info.providerName.getPackageName();
2557 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2558 }
2559 }
2560
2561 /**
2562 * Event handler for the search button
2563 *
2564 * @param v The view that was clicked.
2565 */
2566 public void onClickSearchButton(View v) {
2567 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2568
2569 onSearchRequested();
2570 }
2571
2572 /**
2573 * Event handler for the voice button
2574 *
2575 * @param v The view that was clicked.
2576 */
2577 public void onClickVoiceButton(View v) {
2578 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2579
2580 startVoice();
2581 }
2582
2583 public void startVoice() {
2584 try {
2585 final SearchManager searchManager =
2586 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2587 ComponentName activityName = searchManager.getGlobalSearchActivity();
2588 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2589 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2590 if (activityName != null) {
2591 intent.setPackage(activityName.getPackageName());
2592 }
2593 startActivity(null, intent, "onClickVoiceButton");
2594 } catch (ActivityNotFoundException e) {
2595 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2596 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2597 startActivitySafely(null, intent, "onClickVoiceButton");
2598 }
2599 }
2600
2601 /**
2602 * Event handler for the "grid" button that appears on the home screen, which
2603 * enters all apps mode.
2604 *
2605 * @param v The view that was clicked.
2606 */
2607 protected void onClickAllAppsButton(View v) {
2608 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2609 if (isAllAppsVisible()) {
2610 showWorkspace(true);
2611 } else {
2612 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2613 }
2614 }
2615
2616 private void showBrokenAppInstallDialog(final String packageName,
2617 DialogInterface.OnClickListener onSearchClickListener) {
2618 new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault))
2619 .setTitle(R.string.abandoned_promises_title)
2620 .setMessage(R.string.abandoned_promise_explanation)
2621 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2622 .setNeutralButton(R.string.abandoned_clean_this,
2623 new DialogInterface.OnClickListener() {
2624 public void onClick(DialogInterface dialog, int id) {
2625 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2626 mWorkspace.removeAbandonedPromise(packageName, user);
2627 }
2628 })
2629 .create().show();
2630 return;
2631 }
2632
2633 /**
2634 * Event handler for an app shortcut click.
2635 *
2636 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2637 */
2638 protected void onClickAppShortcut(final View v) {
2639 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2640 Object tag = v.getTag();
2641 if (!(tag instanceof ShortcutInfo)) {
2642 throw new IllegalArgumentException("Input must be a Shortcut");
2643 }
2644
2645 // Open shortcut
2646 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2647 final Intent intent = shortcut.intent;
2648
2649 // Check for special shortcuts
2650 if (intent.getComponent() != null) {
2651 final String shortcutClass = intent.getComponent().getClassName();
2652
2653 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2654 MemoryDumpActivity.startDump(this);
2655 return;
2656 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2657 toggleShowWeightWatcher();
2658 return;
2659 }
2660 }
2661
2662 // Check for abandoned promise
2663 if ((v instanceof BubbleTextView)
2664 && shortcut.isPromise()
2665 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
2666 showBrokenAppInstallDialog(
2667 shortcut.getTargetComponent().getPackageName(),
2668 new DialogInterface.OnClickListener() {
2669 public void onClick(DialogInterface dialog, int id) {
2670 startAppShortcutOrInfoActivity(v);
2671 }
2672 });
2673 return;
2674 }
2675
2676 // Start activities
2677 startAppShortcutOrInfoActivity(v);
2678 }
2679
2680 private void startAppShortcutOrInfoActivity(View v) {
2681 Object tag = v.getTag();
2682 final ShortcutInfo shortcut;
2683 final Intent intent;
2684 if (tag instanceof ShortcutInfo) {
2685 shortcut = (ShortcutInfo) tag;
2686 intent = shortcut.intent;
2687 int[] pos = new int[2];
2688 v.getLocationOnScreen(pos);
2689 intent.setSourceBounds(new Rect(pos[0], pos[1],
2690 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2691
2692 } else if (tag instanceof AppInfo) {
2693 shortcut = null;
2694 intent = ((AppInfo) tag).intent;
2695 } else {
2696 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2697 }
2698
2699 boolean success = startActivitySafely(v, intent, tag);
2700 mStats.recordLaunch(intent, shortcut);
2701
2702 if (success && v instanceof BubbleTextView) {
2703 mWaitingForResume = (BubbleTextView) v;
2704 mWaitingForResume.setStayPressed(true);
2705 }
2706 }
2707
2708 /**
2709 * Event handler for a folder icon click.
2710 *
2711 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2712 */
2713 protected void onClickFolderIcon(View v) {
2714 if (LOGD) Log.d(TAG, "onClickFolder");
2715 if (!(v instanceof FolderIcon)){
2716 throw new IllegalArgumentException("Input must be a FolderIcon");
2717 }
2718
2719 FolderIcon folderIcon = (FolderIcon) v;
2720 final FolderInfo info = folderIcon.getFolderInfo();
2721 Folder openFolder = mWorkspace.getFolderForTag(info);
2722
2723 // If the folder info reports that the associated folder is open, then verify that
2724 // it is actually opened. There have been a few instances where this gets out of sync.
2725 if (info.opened && openFolder == null) {
2726 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2727 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2728 info.opened = false;
2729 }
2730
2731 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2732 // Close any open folder
2733 closeFolder();
2734 // Open the requested folder
2735 openFolder(folderIcon);
2736 } else {
2737 // Find the open folder...
2738 int folderScreen;
2739 if (openFolder != null) {
2740 folderScreen = mWorkspace.getPageForView(openFolder);
2741 // .. and close it
2742 closeFolder(openFolder);
2743 if (folderScreen != mWorkspace.getCurrentPage()) {
2744 // Close any folder open on the current screen
2745 closeFolder();
2746 // Pull the folder onto this screen
2747 openFolder(folderIcon);
2748 }
2749 }
2750 }
2751 }
2752
2753 /**
2754 * Event handler for the (Add) Widgets button that appears after a long press
2755 * on the home screen.
2756 */
2757 protected void onClickAddWidgetButton(View view) {
2758 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
2759 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2760 }
2761
2762 /**
2763 * Event handler for the wallpaper picker button that appears after a long press
2764 * on the home screen.
2765 */
2766 protected void onClickWallpaperPicker(View v) {
2767 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2768 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2769 pickWallpaper.setComponent(getWallpaperPickerComponent());
2770 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2771 }
2772
2773 /**
2774 * Event handler for a click on the settings button that appears after a long press
2775 * on the home screen.
2776 */
2777 protected void onClickSettingsButton(View v) {
2778 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2779 }
2780
2781 public void onTouchDownAllAppsButton(View v) {
2782 // Provide the same haptic feedback that the system offers for virtual keys.
2783 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2784 }
2785
2786 public void performHapticFeedbackOnTouchDown(View v) {
2787 // Provide the same haptic feedback that the system offers for virtual keys.
2788 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2789 }
2790
2791 public View.OnTouchListener getHapticFeedbackTouchListener() {
2792 if (mHapticFeedbackTouchListener == null) {
2793 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2794 @Override
2795 public boolean onTouch(View v, MotionEvent event) {
2796 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2797 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2798 }
2799 return false;
2800 }
2801 };
2802 }
2803 return mHapticFeedbackTouchListener;
2804 }
2805
2806 public void onDragStarted(View view) {}
2807
2808 /**
2809 * Called when the user stops interacting with the launcher.
2810 * This implies that the user is now on the homescreen and is not doing housekeeping.
2811 */
2812 protected void onInteractionEnd() {}
2813
2814 /**
2815 * Called when the user starts interacting with the launcher.
2816 * The possible interactions are:
2817 * - open all apps
2818 * - reorder an app shortcut, or a widget
2819 * - open the overview mode.
2820 * This is a good time to stop doing things that only make sense
2821 * when the user is on the homescreen and not doing housekeeping.
2822 */
2823 protected void onInteractionBegin() {}
2824
2825 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
2826 String packageName = componentName.getPackageName();
2827 try {
2828 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2829 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2830 launcherApps.showAppDetailsForProfile(componentName, user);
2831 } catch (SecurityException e) {
2832 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2833 Log.e(TAG, "Launcher does not have permission to launch settings");
2834 } catch (ActivityNotFoundException e) {
2835 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2836 Log.e(TAG, "Unable to launch settings");
2837 }
2838 }
2839
2840 // returns true if the activity was started
2841 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2842 UserHandleCompat user) {
2843 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
2844 // System applications cannot be installed. For now, show a toast explaining that.
2845 // We may give them the option of disabling apps this way.
2846 int messageId = R.string.uninstall_system_app_text;
2847 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2848 return false;
2849 } else {
2850 String packageName = componentName.getPackageName();
2851 String className = componentName.getClassName();
2852 Intent intent = new Intent(
2853 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2854 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2855 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
2856 if (user != null) {
2857 user.addToIntent(intent, Intent.EXTRA_USER);
2858 }
2859 startActivity(intent);
2860 return true;
2861 }
2862 }
2863
2864 boolean startActivity(View v, Intent intent, Object tag) {
2865 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2866 try {
2867 // Only launch using the new animation if the shortcut has not opted out (this is a
2868 // private contract between launcher and may be ignored in the future).
2869 boolean useLaunchAnimation = (v != null) &&
2870 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2871 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2872 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2873
2874 UserHandleCompat user = null;
2875 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2876 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2877 user = userManager.getUserForSerialNumber(serialNumber);
2878 }
2879
2880 Bundle optsBundle = null;
2881 if (useLaunchAnimation) {
2882 ActivityOptions opts = Utilities.isLmpOrAbove() ?
2883 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim)🔵
2884 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasured🔵
2885 optsBundle = opts.toBundle();
2886 }
2887
2888 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2889 // Could be launching some bookkeeping activity
2890 startActivity(intent, optsBundle);
2891 } else {
2892 // TODO Component can be null when shortcuts are supported for secondary user
2893 launcherApps.startActivityForProfile(intent.getComponent(), user,
2894 intent.getSourceBounds(), optsBundle);
2895 }
2896 return true;
2897 } catch (SecurityException e) {
2898 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2899 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2900 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2901 "or use the exported attribute for this activity. "
2902 + "tag="+ tag + " intent=" + intent, e);
2903 }
2904 return false;
2905 }
2906
2907 boolean startActivitySafely(View v, Intent intent, Object tag) {
2908 boolean success = false;
2909 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2910 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2911 return false;
2912 }
2913 try {
2914 success = startActivity(v, intent, tag);
2915 } catch (ActivityNotFoundException e) {
2916 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2917 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2918 }
2919 return success;
2920 }
2921
2922 /**
2923 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2924 * in the DragLayer in the exact absolute location of the original FolderIcon.
2925 */
2926 private void copyFolderIconToImage(FolderIcon fi) {
2927 final int width = fi.getMeasuredWidth();
2928 final int height = fi.getMeasuredHeight();
2929
2930 // Lazy load ImageView, Bitmap and Canvas
2931 if (mFolderIconImageView == null) {
2932 mFolderIconImageView = new ImageView(this);
2933 }
2934 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2935 mFolderIconBitmap.getHeight() != height) {
2936 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2937 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2938 }
2939
2940 DragLayer.LayoutParams lp;
2941 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2942 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2943 } else {
2944 lp = new DragLayer.LayoutParams(width, height);
2945 }
2946
2947 // The layout from which the folder is being opened may be scaled, adjust the starting
2948 // view size by this scale factor.
2949 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
2950 lp.customPosition = true;
2951 lp.x = mRectForFolderAnimation.left;
2952 lp.y = mRectForFolderAnimation.top;
2953 lp.width = (int) (scale * width);
2954 lp.height = (int) (scale * height);
2955
2956 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2957 fi.draw(mFolderIconCanvas);
2958 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
2959 if (fi.getFolder() != null) {
2960 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2961 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
2962 }
2963 // Just in case this image view is still in the drag layer from a previous animation,
2964 // we remove it and re-add it.
2965 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2966 mDragLayer.removeView(mFolderIconImageView);
2967 }
2968 mDragLayer.addView(mFolderIconImageView, lp);
2969 if (fi.getFolder() != null) {
2970 fi.getFolder().bringToFront();
2971 }
2972 }
2973
2974 private void growAndFadeOutFolderIcon(FolderIcon fi) {
2975 if (fi == null) return;
2976 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2977 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2978 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2979
2980 FolderInfo info = (FolderInfo) fi.getTag();
2981 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2982 CellLayout cl = (CellLayout) fi.getParent().getParent();
2983 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2984 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
2985 }
2986
2987 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
2988 copyFolderIconToImage(fi);
2989 fi.setVisibility(View.INVISIBLE);
2990
2991 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
2992 scaleX, scaleY);
2993 if (Utilities.isLmpOrAbove()) {
2994 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
2995 }
2996 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
2997 oa.start();
2998 }
2999
3000 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
3001 if (fi == null) return;
3002 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3003 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3004 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3005
3006 final CellLayout cl = (CellLayout) fi.getParent().getParent();
3007
3008 // We remove and re-draw the FolderIcon in-case it has changed
3009 mDragLayer.removeView(mFolderIconImageView);
3010 copyFolderIconToImage(fi);
3011 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
3012 scaleX, scaleY);
3013 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
3014 oa.addListener(new AnimatorListenerAdapter() {
3015 @Override
3016 public void onAnimationEnd(Animator animation) {
3017 if (cl != null) {
3018 cl.clearFolderLeaveBehind();
3019 // Remove the ImageView copy of the FolderIcon and make the original visible.
3020 mDragLayer.removeView(mFolderIconImageView);
3021 fi.setVisibility(View.VISIBLE);
3022 }
3023 }
3024 });
3025 oa.start();
3026 }
3027
3028 /**
3029 * Opens the user folder described by the specified tag. The opening of the folder
3030 * is animated relative to the specified View. If the View is null, no animation
3031 * is played.
3032 *
3033 * @param folderInfo The FolderInfo describing the folder to open.
3034 */
3035 public void openFolder(FolderIcon folderIcon) {
3036 Folder folder = folderIcon.getFolder();
3037 FolderInfo info = folder.mInfo;
3038
3039 info.opened = true;
3040
3041 // Just verify that the folder hasn't already been added to the DragLayer.
3042 // There was a one-off crash where the folder had a parent already.
3043 if (folder.getParent() == null) {
3044 mDragLayer.addView(folder);
3045 mDragController.addDropTarget((DropTarget) folder);
3046 } else {
3047 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3048 folder.getParent() + ").");
3049 }
3050 folder.animateOpen();
3051 growAndFadeOutFolderIcon(folderIcon);
3052
3053 // Notify the accessibility manager that this folder "window" has appeared and occluded
3054 // the workspace items
3055 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3056 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
3057 }
3058
3059 public void closeFolder() {
3060 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3061 if (folder != null) {
3062 if (folder.isEditingName()) {
3063 folder.dismissEditingName();
3064 }
3065 closeFolder(folder);
3066 }
3067 }
3068
3069 void closeFolder(Folder folder) {
3070 folder.getInfo().opened = false;
3071
3072 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3073 if (parent != null) {
3074 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3075 shrinkAndFadeInFolderIcon(fi);
3076 }
3077 folder.animateClosed();
3078
3079 // Notify the accessibility manager that this folder "window" has disappeard and no
3080 // longer occludeds the workspace items
3081 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3082 }
3083
3084 public boolean onLongClick(View v) {
3085 if (!isDraggingEnabled()) return false;
3086 if (isWorkspaceLocked()) return false;
3087 if (mState != State.WORKSPACE) return false;
3088
3089 if (v instanceof Workspace) {
3090 if (!mWorkspace.isInOverviewMode()) {
3091 if (mWorkspace.enterOverviewMode()) {
3092 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3093 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3094 return true;
3095 } else {
3096 return false;
3097 }
3098 } else {
3099 return false;
3100 }
3101 }
3102
3103 CellLayout.CellInfo longClickCellInfo = null;
3104 View itemUnderLongClick = null;
3105 if (v.getTag() instanceof ItemInfo) {
3106 ItemInfo info = (ItemInfo) v.getTag();
3107 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3108 itemUnderLongClick = longClickCellInfo.cell;
3109 resetAddInfo();
3110 }
3111
3112 // The hotseat touch handling does not go through Workspace, and we always allow long press
3113 // on hotseat items.
3114 final boolean inHotseat = isHotseatLayout(v);
3115 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
3116 if (allowLongPress && !mDragController.isDragging()) {
3117 if (itemUnderLongClick == null) {
3118 // User long pressed on empty space
3119 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3120 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3121 if (mWorkspace.isInOverviewMode()) {
3122 mWorkspace.startReordering(v);
3123 } else {
3124 mWorkspace.enterOverviewMode();
3125 }
3126 } else {
3127 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3128 mHotseat.getOrderInHotseat(
3129 longClickCellInfo.cellX,
3130 longClickCellInfo.cellY));
3131 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
3132 // User long pressed on an item
3133 mWorkspace.startDrag(longClickCellInfo);
3134 }
3135 }
3136 }
3137 return true;
3138 }
3139
3140 boolean isHotseatLayout(View layout) {
3141 return mHotseat != null && layout != null &&
3142 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3143 }
3144
3145 /**
3146 * Returns the CellLayout of the specified container at the specified screen.
3147 */
3148 CellLayout getCellLayout(long container, long screenId) {
3149 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3150 if (mHotseat != null) {
3151 return mHotseat.getLayout();
3152 } else {
3153 return null;
3154 }
3155 } else {
3156 return (CellLayout) mWorkspace.getScreenWithId(screenId);
3157 }
3158 }
3159
3160 public boolean isAllAppsVisible() {
3161 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
3162 }
3163
3164 private void setWorkspaceBackground(boolean workspace) {
3165 mLauncherView.setBackground(workspace ?
3166 mWorkspaceBackgroundDrawable : null);
3167 }
3168
3169 protected void changeWallpaperVisiblity(boolean visible) {
3170 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3171 int curflags = getWindow().getAttributes().flags
3172 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3173 if (wpflags != curflags) {
3174 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3175 }
3176 setWorkspaceBackground(visible);
3177 }
3178
3179 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3180 if (v instanceof LauncherTransitionable) {
3181 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3182 }
3183 }
3184
3185 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3186 if (v instanceof LauncherTransitionable) {
3187 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3188 }
3189
3190 // Update the workspace transition step as well
3191 dispatchOnLauncherTransitionStep(v, 0f);
3192 }
3193
3194 private void dispatchOnLauncherTransitionStep(View v, float t) {
3195 if (v instanceof LauncherTransitionable) {
3196 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3197 }
3198 }
3199
3200 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3201 if (v instanceof LauncherTransitionable) {
3202 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3203 }
3204
3205 // Update the workspace transition step as well
3206 dispatchOnLauncherTransitionStep(v, 1f);
3207 }
3208
3209 /**
3210 * Things to test when changing the following seven functions.
3211 * - Home from workspace
3212 * - from center screen
3213 * - from other screens
3214 * - Home from all apps
3215 * - from center screen
3216 * - from other screens
3217 * - Back from all apps
3218 * - from center screen
3219 * - from other screens
3220 * - Launch app from workspace and quit
3221 * - with back
3222 * - with home
3223 * - Launch app from all apps and quit
3224 * - with back
3225 * - with home
3226 * - Go to a screen that's not the default, then all
3227 * apps, and launch and app, and go back
3228 * - with back
3229 * -with home
3230 * - On workspace, long press power and go back
3231 * - with back
3232 * - with home
3233 * - On all apps, long press power and go back
3234 * - with back
3235 * - with home
3236 * - On workspace, power off
3237 * - On all apps, power off
3238 * - Launch an app and turn off the screen while in that app
3239 * - Go back with home key
3240 * - Go back with back key TODO: make this not go to workspace
3241 * - From all apps
3242 * - From workspace
3243 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3244 * - From all apps
3245 * - From the center workspace
3246 * - From another workspace
3247 */
3248
3249 /**
3250 * Zoom the camera out from the workspace to reveal 'toView'.
3251 * Assumes that the view to show is anchored at either the very top or very bottom
3252 * of the screen.
3253 */
3254 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
3255 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3256 showAppsCustomizeHelper(animated, springLoaded, contentType);
3257 }
3258
3259 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3260 final AppsCustomizePagedView.ContentType contentType) {
3261 if (mStateAnimation != null) {
3262 mStateAnimation.setDuration(0);
3263 mStateAnimation.cancel();
3264 mStateAnimation = null;
3265 }
3266
3267 boolean material = Utilities.isLmpOrAbove();
3268
3269 final Resources res = getResources();
3270
3271 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3272 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3273 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
3274 final int itemsAlphaStagger =
3275 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3276
3277 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3278 final View fromView = mWorkspace;
3279 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
3280
3281 final ArrayList<View> layerViews = new ArrayList<View>();
3282
3283 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3284 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
3285 Animator workspaceAnim =
3286 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
3287 if (!LauncherAppState.isDisableAllApps()
3288 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3289 // Set the content type for the all apps/widgets space
3290 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3291 }
3292
3293 // If for some reason our views aren't initialized, don't animate
3294 boolean initialized = getAllAppsButton() != null;
3295
3296 if (animated && initialized) {
3297 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3298 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3299 toView.findViewById(R.id.apps_customize_pane_content);
3300
3301 final View page = content.getPageAt(content.getCurrentPage());
3302 final View revealView = toView.findViewById(R.id.fake_page);
3303
3304 final float initialPanelAlpha = 1f;
3305
3306 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3307 if (isWidgetTray) {
3308 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3309 } else {
3310 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3311 }
3312
3313 // Hide the real page background, and swap in the fake one
3314 content.setPageBackgroundsVisible(false);
3315 revealView.setVisibility(View.VISIBLE);
3316 // We need to hide this view as the animation start will be posted.
3317 revealView.setAlpha(0);
3318
3319 int width = revealView.getMeasuredWidth();
3320 int height = revealView.getMeasuredHeight();
3321 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3322
3323 revealView.setTranslationY(0);
3324 revealView.setTranslationX(0);
3325
3326 // Get the y delta between the center of the page and the center of the all apps button
3327 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3328 getAllAppsButton(), null);
3329
3330 float alpha = 0;
3331 float xDrift = 0;
3332 float yDrift = 0;
3333 if (material) {
3334 alpha = isWidgetTray ? 0.3f : 1f;
3335 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3336 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3337 } else {
3338 yDrift = 2 * height / 3;
3339 xDrift = 0;
3340 }
3341 final float initAlpha = alpha;
3342
3343 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3344 layerViews.add(revealView);
3345 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
3346 PropertyValuesHolder panelDriftY =
3347 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
3348 PropertyValuesHolder panelDriftX =
3349 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
3350
3351 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3352 panelAlpha, panelDriftY, panelDriftX);
3353
3354 panelAlphaAndDrift.setDuration(revealDuration);
3355 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3356
3357 mStateAnimation.play(panelAlphaAndDrift);
3358
3359 if (page != null) {
3360 page.setVisibility(View.VISIBLE);
3361 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3362 layerViews.add(page);
3363
3364 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3365 page.setTranslationY(yDrift);
3366 pageDrift.setDuration(revealDuration);
3367 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3368 pageDrift.setStartDelay(itemsAlphaStagger);
3369 mStateAnimation.play(pageDrift);
3370
3371 page.setAlpha(0f);
3372 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
3373 itemsAlpha.setDuration(revealDuration);
3374 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3375 itemsAlpha.setStartDelay(itemsAlphaStagger);
3376 mStateAnimation.play(itemsAlpha);
3377 }
3378
3379 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3380 pageIndicators.setAlpha(0.01f);
3381 ObjectAnimator indicatorsAlpha =
3382 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
3383 indicatorsAlpha.setDuration(revealDuration);
3384 mStateAnimation.play(indicatorsAlpha);
3385
3386 if (material) {
3387 final View allApps = getAllAppsButton();
3388 int allAppsButtonSize = LauncherAppState.getInstance().
3389 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3390 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3391 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3392 height / 2, startRadius, revealRadius);
3393 reveal.setDuration(revealDuration);
3394 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3395
3396 reveal.addListener(new AnimatorListenerAdapter() {
3397 public void onAnimationStart(Animator animation) {
3398 if (!isWidgetTray) {
3399 allApps.setVisibility(View.INVISIBLE);
3400 }
3401 }
3402 public void onAnimationEnd(Animator animation) {
3403 if (!isWidgetTray) {
3404 allApps.setVisibility(View.VISIBLE);
3405 }
3406 }
3407 });
3408 mStateAnimation.play(reveal);
3409 }
3410
3411 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3412 @Override
3413 public void onAnimationEnd(Animator animation) {
3414 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3415 dispatchOnLauncherTransitionEnd(toView, animated, false);
3416
3417 revealView.setVisibility(View.INVISIBLE);
3418 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3419 if (page != null) {
3420 page.setLayerType(View.LAYER_TYPE_NONE, null);
3421 }
3422 content.setPageBackgroundsVisible(true);
3423
3424 // Hide the search bar
3425 if (mSearchDropTargetBar != null) {
3426 mSearchDropTargetBar.hideSearchBar(false);
3427 }
3428 }
3429
3430 });
3431
3432 if (workspaceAnim != null) {
3433 mStateAnimation.play(workspaceAnim);
3434 }
3435
3436 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3437 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3438 final AnimatorSet stateAnimation = mStateAnimation;
3439 final Runnable startAnimRunnable = new Runnable() {
3440 public void run() {
3441 // Check that mStateAnimation hasn't changed while
3442 // we waited for a layout/draw pass
3443 if (mStateAnimation != stateAnimation)
3444 return;
3445 dispatchOnLauncherTransitionStart(fromView, animated, false);
3446 dispatchOnLauncherTransitionStart(toView, animated, false);
3447
3448 revealView.setAlpha(initAlpha);
3449 if (Utilities.isLmpOrAbove()) {
3450 for (int i = 0; i < layerViews.size(); i++) {
3451 View v = layerViews.get(i);
3452 if (v != null) {
3453 boolean attached = true;
3454 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3455 attached = v.isAttachedToWindow();
3456 }
3457 if (attached) v.buildLayer();
3458 }
3459 }
3460 }
3461 mStateAnimation.start();
3462 }
3463 };
3464 toView.bringToFront();
3465 toView.setVisibility(View.VISIBLE);
3466 toView.post(startAnimRunnable);
3467 } else {
3468 toView.setTranslationX(0.0f);
3469 toView.setTranslationY(0.0f);
3470 toView.setScaleX(1.0f);
3471 toView.setScaleY(1.0f);
3472 toView.setVisibility(View.VISIBLE);
3473 toView.bringToFront();
3474
3475 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
3476 // Hide the search bar
3477 if (mSearchDropTargetBar != null) {
3478 mSearchDropTargetBar.hideSearchBar(false);
3479 }
3480 }
3481 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3482 dispatchOnLauncherTransitionStart(fromView, animated, false);
3483 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3484 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3485 dispatchOnLauncherTransitionStart(toView, animated, false);
3486 dispatchOnLauncherTransitionEnd(toView, animated, false);
3487 }
3488 }
3489
3490 /**
3491 * Zoom the camera back into the workspace, hiding 'fromView'.
3492 * This is the opposite of showAppsCustomizeHelper.
3493 * @param animated If true, the transition will be animated.
3494 */
3495 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
3496 final boolean springLoaded, final Runnable onCompleteRunnable) {
3497
3498 if (mStateAnimation != null) {
3499 mStateAnimation.setDuration(0);
3500 mStateAnimation.cancel();
3501 mStateAnimation = null;
3502 }
3503
3504 boolean material = Utilities.isLmpOrAbove();
3505 Resources res = getResources();
3506
3507 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
3508 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3509 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
3510 final int itemsAlphaStagger =
3511 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3512
3513 final float scaleFactor = (float)
3514 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3515 final View fromView = mAppsCustomizeTabHost;
3516 final View toView = mWorkspace;
3517 Animator workspaceAnim = null;
3518 final ArrayList<View> layerViews = new ArrayList<View>();
3519
3520 if (toState == Workspace.State.NORMAL) {
3521 workspaceAnim = mWorkspace.getChangeStateAnimation(
3522 toState, animated, layerViews);
3523 } else if (toState == Workspace.State.SPRING_LOADED ||
3524 toState == Workspace.State.OVERVIEW) {
3525 workspaceAnim = mWorkspace.getChangeStateAnimation(
3526 toState, animated, layerViews);
3527 }
3528
3529 // If for some reason our views aren't initialized, don't animate
3530 boolean initialized = getAllAppsButton() != null;
3531
3532 if (animated && initialized) {
3533 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3534 if (workspaceAnim != null) {
3535 mStateAnimation.play(workspaceAnim);
3536 }
3537
3538 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3539 fromView.findViewById(R.id.apps_customize_pane_content);
3540
3541 final View page = content.getPageAt(content.getNextPage());
3542
3543 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3544 int count = content.getChildCount();
3545 for (int i = 0; i < count; i++) {
3546 View child = content.getChildAt(i);
3547 if (child != page) {
3548 child.setVisibility(View.INVISIBLE);
3549 }
3550 }
3551 final View revealView = fromView.findViewById(R.id.fake_page);
3552
3553 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3554 // don't perform all these no-op animations. In particularly, this was causing
3555 // the all-apps button to pop in and out.
3556 if (fromView.getVisibility() == View.VISIBLE) {
3557 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3558 final boolean isWidgetTray =
3559 contentType == AppsCustomizePagedView.ContentType.Widgets;
3560
3561 if (isWidgetTray) {
3562 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3563 } else {
3564 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3565 }
3566
3567 int width = revealView.getMeasuredWidth();
3568 int height = revealView.getMeasuredHeight();
3569 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3570
3571 // Hide the real page background, and swap in the fake one
3572 revealView.setVisibility(View.VISIBLE);
3573 content.setPageBackgroundsVisible(false);
3574
3575 final View allAppsButton = getAllAppsButton();
3576 revealView.setTranslationY(0);
3577 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3578 allAppsButton, null);
3579
3580 float xDrift = 0;
3581 float yDrift = 0;
3582 if (material) {
3583 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3584 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3585 } else {
3586 yDrift = 5 * height / 4;
3587 xDrift = 0;
3588 }
3589
3590 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3591 TimeInterpolator decelerateInterpolator = material ?
3592 new LogDecelerateInterpolator(100, 0) :
3593 new LogDecelerateInterpolator(30, 0);
3594
3595 // The vertical motion of the apps panel should be delayed by one frame
3596 // from the conceal animation in order to give the right feel. We correpsondingly
3597 // shorten the duration so that the slide and conceal end at the same time.
3598 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3599 0, yDrift);
3600 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3601 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3602 panelDriftY.setInterpolator(decelerateInterpolator);
3603 mStateAnimation.play(panelDriftY);
3604
3605 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3606 0, xDrift);
3607 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3608 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3609 panelDriftX.setInterpolator(decelerateInterpolator);
3610 mStateAnimation.play(panelDriftX);
3611
3612 if (isWidgetTray || !material) {
3613 float finalAlpha = material ? 0.4f : 0f;
3614 revealView.setAlpha(1f);
3615 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3616 1f, finalAlpha);
3617 panelAlpha.setDuration(revealDuration);
3618 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3619 new AccelerateInterpolator(1.5f));
3620 mStateAnimation.play(panelAlpha);
3621 }
3622
3623 if (page != null) {
3624 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3625
3626 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3627 0, yDrift);
3628 page.setTranslationY(0);
3629 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3630 pageDrift.setInterpolator(decelerateInterpolator);
3631 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3632 mStateAnimation.play(pageDrift);
3633
3634 page.setAlpha(1f);
3635 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3636 itemsAlpha.setDuration(100);
3637 itemsAlpha.setInterpolator(decelerateInterpolator);
3638 mStateAnimation.play(itemsAlpha);
3639 }
3640
3641 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3642 pageIndicators.setAlpha(1f);
3643 ObjectAnimator indicatorsAlpha =
3644 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3645 indicatorsAlpha.setDuration(revealDuration);
3646 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3647 mStateAnimation.play(indicatorsAlpha);
3648
3649 width = revealView.getMeasuredWidth();
3650
3651 if (material) {
3652 if (!isWidgetTray) {
3653 allAppsButton.setVisibility(View.INVISIBLE);
3654 }
3655 int allAppsButtonSize = LauncherAppState.getInstance().
3656 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3657 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3658 Animator reveal =
3659 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3660 height / 2, revealRadius, finalRadius);
3661 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3662 reveal.setDuration(revealDuration);
3663 reveal.setStartDelay(itemsAlphaStagger);
3664
3665 reveal.addListener(new AnimatorListenerAdapter() {
3666 public void onAnimationEnd(Animator animation) {
3667 revealView.setVisibility(View.INVISIBLE);
3668 if (!isWidgetTray) {
3669 allAppsButton.setVisibility(View.VISIBLE);
3670 }
3671 }
3672 });
3673
3674 mStateAnimation.play(reveal);
3675 }
3676
3677 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3678 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3679 mAppsCustomizeContent.stopScrolling();
3680 }
3681
3682 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3683 @Override
3684 public void onAnimationEnd(Animator animation) {
3685 fromView.setVisibility(View.GONE);
3686 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3687 dispatchOnLauncherTransitionEnd(toView, animated, true);
3688 if (onCompleteRunnable != null) {
3689 onCompleteRunnable.run();
3690 }
3691
3692 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3693 if (page != null) {
3694 page.setLayerType(View.LAYER_TYPE_NONE, null);
3695 }
3696 content.setPageBackgroundsVisible(true);
3697 // Unhide side pages
3698 int count = content.getChildCount();
3699 for (int i = 0; i < count; i++) {
3700 View child = content.getChildAt(i);
3701 child.setVisibility(View.VISIBLE);
3702 }
3703
3704 // Reset page transforms
3705 if (page != null) {
3706 page.setTranslationX(0);
3707 page.setTranslationY(0);
3708 page.setAlpha(1);
3709 }
3710 content.setCurrentPage(content.getNextPage());
3711
3712 mAppsCustomizeContent.updateCurrentPageScroll();
3713 }
3714 });
3715
3716 final AnimatorSet stateAnimation = mStateAnimation;
3717 final Runnable startAnimRunnable = new Runnable() {
3718 public void run() {
3719 // Check that mStateAnimation hasn't changed while
3720 // we waited for a layout/draw pass
3721 if (mStateAnimation != stateAnimation)
3722 return;
3723 dispatchOnLauncherTransitionStart(fromView, animated, false);
3724 dispatchOnLauncherTransitionStart(toView, animated, false);
3725
3726 if (Utilities.isLmpOrAbove()) {
3727 for (int i = 0; i < layerViews.size(); i++) {
3728 View v = layerViews.get(i);
3729 if (v != null) {
3730 boolean attached = true;
3731 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3732 attached = v.isAttachedToWindow();
3733 }
3734 if (attached) v.buildLayer();
3735 }
3736 }
3737 }
3738 mStateAnimation.start();
3739 }
3740 };
3741 fromView.post(startAnimRunnable);
3742 } else {
3743 fromView.setVisibility(View.GONE);
3744 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3745 dispatchOnLauncherTransitionStart(fromView, animated, true);
3746 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3747 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3748 dispatchOnLauncherTransitionStart(toView, animated, true);
3749 dispatchOnLauncherTransitionEnd(toView, animated, true);
3750 }
3751 }
3752
3753 @Override
3754 public void onTrimMemory(int level) {
3755 super.onTrimMemory(level);
3756 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
3757 mAppsCustomizeTabHost.onTrimMemory();
3758 }
3759 }
3760
3761 protected void showWorkspace(boolean animated) {
3762 showWorkspace(animated, null);
3763 }
3764
3765 protected void showWorkspace() {
3766 showWorkspace(true);
3767 }
3768
3769 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
3770 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
3771 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
3772 mWorkspace.setVisibility(View.VISIBLE);
3773 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
3774
3775 // Show the search bar (only animate if we were showing the drop target bar in spring
3776 // loaded mode)
3777 if (mSearchDropTargetBar != null) {
3778 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
3779 }
3780
3781 // Set focus to the AppsCustomize button
3782 if (mAllAppsButton != null) {
3783 mAllAppsButton.requestFocus();
3784 }
3785 }
3786
3787 // Change the state *after* we've called all the transition code
3788 mState = State.WORKSPACE;
3789
3790 // Resume the auto-advance of widgets
3791 mUserPresent = true;
3792 updateRunning();
3793
3794 // Send an accessibility event to announce the context change
3795 getWindow().getDecorView()
3796 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3797
3798 onWorkspaceShown(animated);
3799 }
3800
3801 void showOverviewMode(boolean animated) {
3802 mWorkspace.setVisibility(View.VISIBLE);
3803 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3804 mState = State.WORKSPACE;
3805 onWorkspaceShown(animated);
3806 }
3807
3808 public void onWorkspaceShown(boolean animated) {
3809 }
3810
3811 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3812 boolean resetPageToZero) {
3813 if (mState != State.WORKSPACE) return;
3814
3815 if (resetPageToZero) {
3816 mAppsCustomizeTabHost.reset();
3817 }
3818 showAppsCustomizeHelper(animated, false, contentType);
3819 mAppsCustomizeTabHost.post(new Runnable() {
3820 @Override
3821 public void run() {
3822 // We post this in-case the all apps view isn't yet constructed.
3823 mAppsCustomizeTabHost.requestFocus();
3824 }
3825 });
3826
3827 // Change the state *after* we've called all the transition code
3828 mState = State.APPS_CUSTOMIZE;
3829
3830 // Pause the auto-advance of widgets until we are out of AllApps
3831 mUserPresent = false;
3832 updateRunning();
3833 closeFolder();
3834
3835 // Send an accessibility event to announce the context change
3836 getWindow().getDecorView()
3837 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3838 }
3839
3840 void enterSpringLoadedDragMode() {
3841 if (isAllAppsVisible()) {
3842 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
3843 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
3844 }
3845 }
3846
3847 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
3848 final Runnable onCompleteRunnable) {
3849 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3850
3851 mHandler.postDelayed(new Runnable() {
3852 @Override
3853 public void run() {
3854 if (successfulDrop) {
3855 // Before we show workspace, hide all apps again because
3856 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3857 // clean up our state transition functions
3858 mAppsCustomizeTabHost.setVisibility(View.GONE);
3859 showWorkspace(true, onCompleteRunnable);
3860 } else {
3861 exitSpringLoadedDragMode();
3862 }
3863 }
3864 }, delay);
3865 }
3866
3867 void exitSpringLoadedDragMode() {
3868 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
3869 final boolean animated = true;
3870 final boolean springLoaded = true;
3871 showAppsCustomizeHelper(animated, springLoaded);
3872 mState = State.APPS_CUSTOMIZE;
3873 }
3874 // Otherwise, we are not in spring loaded mode, so don't do anything.
3875 }
3876
3877 void lockAllApps() {
3878 // TODO
3879 }
3880
3881 void unlockAllApps() {
3882 // TODO
3883 }
3884
3885 /**
3886 * Hides the hotseat area.
3887 */
3888 void hideHotseat(boolean animated) {
3889 if (!LauncherAppState.getInstance().isScreenLarge()) {
3890 if (animated) {
3891 if (mHotseat.getAlpha() != 0f) {
3892 int duration = 0;
3893 if (mSearchDropTargetBar != null) {
3894 duration = mSearchDropTargetBar.getTransitionOutDuration();
3895 }
3896 mHotseat.animate().alpha(0f).setDuration(duration);
3897 }
3898 } else {
3899 mHotseat.setAlpha(0f);
3900 }
3901 }
3902 }
3903
3904 /**
3905 * Add an item from all apps or customize onto the given workspace screen.
3906 * If layout is null, add to the current screen.
3907 */
3908 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
3909 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
3910 showOutOfSpaceMessage(isHotseatLayout(layout));
3911 }
3912 }
3913
3914 /** Maps the current orientation to an index for referencing orientation correct global icons */
3915 private int getCurrentOrientationIndexForGlobalIcons() {
3916 // default - 0, landscape - 1
3917 switch (getResources().getConfiguration().orientation) {
3918 case Configuration.ORIENTATION_LANDSCAPE:
3919 return 1;
3920 default:
3921 return 0;
3922 }
3923 }
3924
3925 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
3926 try {
3927 PackageManager packageManager = getPackageManager();
3928 // Look for the toolbar icon specified in the activity meta-data
3929 Bundle metaData = packageManager.getActivityInfo(
3930 activityName, PackageManager.GET_META_DATA).metaData;
3931 if (metaData != null) {
3932 int iconResId = metaData.getInt(resourceName);
3933 if (iconResId != 0) {
3934 Resources res = packageManager.getResourcesForActivity(activityName);
3935 return res.getDrawable(iconResId);
3936 }
3937 }
3938 } catch (NameNotFoundException e) {
3939 // This can happen if the activity defines an invalid drawable
3940 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3941 " not found", e);
3942 } catch (Resources.NotFoundException nfe) {
3943 // This can happen if the activity defines an invalid drawable
3944 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3945 nfe);
3946 }
3947 return null;
3948 }
3949
3950 // if successful in getting icon, return it; otherwise, set button to use default drawable
3951 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
3952 int buttonId, ComponentName activityName, int fallbackDrawableId,
3953 String toolbarResourceName) {
3954 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
3955 Resources r = getResources();
3956 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3957 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3958
3959 TextView button = (TextView) findViewById(buttonId);
3960 // If we were unable to find the icon via the meta-data, use a generic one
3961 if (toolbarIcon == null) {
3962 toolbarIcon = r.getDrawable(fallbackDrawableId);
3963 toolbarIcon.setBounds(0, 0, w, h);
3964 if (button != null) {
3965 button.setCompoundDrawables(toolbarIcon, null, null, null);
3966 }
3967 return null;
3968 } else {
3969 toolbarIcon.setBounds(0, 0, w, h);
3970 if (button != null) {
3971 button.setCompoundDrawables(toolbarIcon, null, null, null);
3972 }
3973 return toolbarIcon.getConstantState();
3974 }
3975 }
3976
3977 // if successful in getting icon, return it; otherwise, set button to use default drawable
3978 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
3979 int buttonId, ComponentName activityName, int fallbackDrawableId,
3980 String toolbarResourceName) {
3981 ImageView button = (ImageView) findViewById(buttonId);
3982 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
3983
3984 if (button != null) {
3985 // If we were unable to find the icon via the meta-data, use a
3986 // generic one
3987 if (toolbarIcon == null) {
3988 button.setImageResource(fallbackDrawableId);
3989 } else {
3990 button.setImageDrawable(toolbarIcon);
3991 }
3992 }
3993
3994 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
3995
3996 }
3997
3998 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
3999 TextView button = (TextView) findViewById(buttonId);
4000 button.setCompoundDrawables(d, null, null, null);
4001 }
4002
4003 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
4004 ImageView button = (ImageView) findViewById(buttonId);
4005 button.setImageDrawable(d.newDrawable(getResources()));
4006 }
4007
4008 private void invalidatePressedFocusedStates(View container, View button) {
4009 if (container instanceof HolographicLinearLayout) {
4010 HolographicLinearLayout layout = (HolographicLinearLayout) container;
4011 layout.invalidatePressedFocusedStates();
4012 } else if (button instanceof HolographicImageView) {
4013 HolographicImageView view = (HolographicImageView) button;
4014 view.invalidatePressedFocusedStates();
4015 }
4016 }
4017
4018 public View getQsbBar() {
4019 if (mQsb == null) {
4020 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
4021 mSearchDropTargetBar.addView(mQsb);
4022 }
4023 return mQsb;
4024 }
4025
4026 protected boolean updateGlobalSearchIcon() {
4027 final View searchButtonContainer = findViewById(R.id.search_button_container);
4028 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
4029 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4030 final View voiceButton = findViewById(R.id.voice_button);
4031
4032 final SearchManager searchManager =
4033 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4034 ComponentName activityName = searchManager.getGlobalSearchActivity();
4035 if (activityName != null) {
4036 int coi = getCurrentOrientationIndexForGlobalIcons();
4037 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4038 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4039 TOOLBAR_SEARCH_ICON_METADATA_NAME);
4040 if (sGlobalSearchIcon[coi] == null) {
4041 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4042 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4043 TOOLBAR_ICON_METADATA_NAME);
4044 }
4045
4046 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
4047 searchButton.setVisibility(View.VISIBLE);
4048 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4049 return true;
4050 } else {
4051 // We disable both search and voice search when there is no global search provider
4052 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
4053 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4054 if (searchButton != null) searchButton.setVisibility(View.GONE);
4055 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4056 updateVoiceButtonProxyVisible(false);
4057 return false;
4058 }
4059 }
4060
4061 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
4062 final View searchButtonContainer = findViewById(R.id.search_button_container);
4063 final View searchButton = (ImageView) findViewById(R.id.search_button);
4064 updateButtonWithDrawable(R.id.search_button, d);
4065 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4066 }
4067
4068 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
4069 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4070 final View voiceButton = findViewById(R.id.voice_button);
4071
4072 // We only show/update the voice search icon if the search icon is enabled as well
4073 final SearchManager searchManager =
4074 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4075 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
4076
4077 ComponentName activityName = null;
4078 if (globalSearchActivity != null) {
4079 // Check if the global search activity handles voice search
4080 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4081 intent.setPackage(globalSearchActivity.getPackageName());
4082 activityName = intent.resolveActivity(getPackageManager());
4083 }
4084
4085 if (activityName == null) {
4086 // Fallback: check if an activity other than the global search activity
4087 // resolves this
4088 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4089 activityName = intent.resolveActivity(getPackageManager());
4090 }
4091 if (searchVisible && activityName != null) {
4092 int coi = getCurrentOrientationIndexForGlobalIcons();
4093 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4094 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4095 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
4096 if (sVoiceSearchIcon[coi] == null) {
4097 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4098 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4099 TOOLBAR_ICON_METADATA_NAME);
4100 }
4101 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
4102 voiceButton.setVisibility(View.VISIBLE);
4103 updateVoiceButtonProxyVisible(false);
4104 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4105 return true;
4106 } else {
4107 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4108 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4109 updateVoiceButtonProxyVisible(false);
4110 return false;
4111 }
4112 }
4113
4114 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
4115 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4116 final View voiceButton = findViewById(R.id.voice_button);
4117 updateButtonWithDrawable(R.id.voice_button, d);
4118 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4119 }
4120
4121 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
4122 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4123 if (voiceButtonProxy != null) {
4124 boolean visible = !forceDisableVoiceButtonProxy &&
4125 mWorkspace.shouldVoiceButtonProxyBeVisible();
4126 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
4127 voiceButtonProxy.bringToFront();
4128 }
4129 }
4130
4131 /**
4132 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button🔵
4133 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4134 */
4135 public void disableVoiceButtonProxy(boolean disabled) {
4136 updateVoiceButtonProxyVisible(disabled);
4137 }
4138
4139 @Override
4140 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
4141 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
4142 final List<CharSequence> text = event.getText();
4143 text.clear();
4144 // Populate event with a fake title based on the current state.
4145 if (mState == State.APPS_CUSTOMIZE) {
4146 text.add(mAppsCustomizeTabHost.getContentTag());
4147 } else {
4148 text.add(getString(R.string.all_apps_home_button_label));
4149 }
4150 return result;
4151 }
4152
4153 /**
4154 * Receives notifications when system dialogs are to be closed.
4155 */
4156 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4157 @Override
4158 public void onReceive(Context context, Intent intent) {
4159 closeSystemDialogs();
4160 }
4161 }
4162
4163 /**
4164 * Receives notifications whenever the appwidgets are reset.
4165 */
4166 private class AppWidgetResetObserver extends ContentObserver {
4167 public AppWidgetResetObserver() {
4168 super(new Handler());
4169 }
4170
4171 @Override
4172 public void onChange(boolean selfChange) {
4173 onAppWidgetReset();
4174 }
4175 }
4176
4177 /**
4178 * If the activity is currently paused, signal that we need to run the passed Runnable
4179 * in onResume.
4180 *
4181 * This needs to be called from incoming places where resources might have been loaded
4182 * while we are paused. That is becaues the Configuration might be wrong
4183 * when we're not running, and if it comes back to what it was when we
4184 * were paused, we are not restarted.
4185 *
4186 * Implementation of the method from LauncherModel.Callbacks.
4187 *
4188 * @return true if we are currently paused. The caller might be able to
4189 * skip some work in that case since we will come back again.
4190 */
4191 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
4192 if (mPaused) {
4193 Log.i(TAG, "Deferring update until onResume");
4194 if (deletePreviousRunnables) {
4195 while (mBindOnResumeCallbacks.remove(run)) {
4196 }
4197 }
4198 mBindOnResumeCallbacks.add(run);
4199 return true;
4200 } else {
4201 return false;
4202 }
4203 }
4204
4205 private boolean waitUntilResume(Runnable run) {
4206 return waitUntilResume(run, false);
4207 }
4208
4209 public void addOnResumeCallback(Runnable run) {
4210 mOnResumeCallbacks.add(run);
4211 }
4212
4213 /**
4214 * If the activity is currently paused, signal that we need to re-run the loader
4215 * in onResume.
4216 *
4217 * This needs to be called from incoming places where resources might have been loaded
4218 * while we are paused. That is becaues the Configuration might be wrong
4219 * when we're not running, and if it comes back to what it was when we
4220 * were paused, we are not restarted.
4221 *
4222 * Implementation of the method from LauncherModel.Callbacks.
4223 *
4224 * @return true if we are currently paused. The caller might be able to
4225 * skip some work in that case since we will come back again.
4226 */
4227 public boolean setLoadOnResume() {
4228 if (mPaused) {
4229 Log.i(TAG, "setLoadOnResume");
4230 mOnResumeNeedsLoad = true;
4231 return true;
4232 } else {
4233 return false;
4234 }
4235 }
4236
4237 /**
4238 * Implementation of the method from LauncherModel.Callbacks.
4239 */
4240 public int getCurrentWorkspaceScreen() {
4241 if (mWorkspace != null) {
4242 return mWorkspace.getCurrentPage();
4243 } else {
4244 return SCREEN_COUNT / 2;
4245 }
4246 }
4247
4248 /**
4249 * Refreshes the shortcuts shown on the workspace.
4250 *
4251 * Implementation of the method from LauncherModel.Callbacks.
4252 */
4253 public void startBinding() {
4254 setWorkspaceLoading(true);
4255
4256 // If we're starting binding all over again, clear any bind calls we'd postponed in
4257 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4258 // from scratch again
4259 mBindOnResumeCallbacks.clear();
4260
4261 // Clear the workspace because it's going to be rebound
4262 mWorkspace.clearDropTargets();
4263 mWorkspace.removeAllWorkspaceScreens();
4264
4265 mWidgetsToAdvance.clear();
4266 if (mHotseat != null) {
4267 mHotseat.resetLayout();
4268 }
4269 }
4270
4271 @Override
4272 public void bindScreens(ArrayList<Long> orderedScreenIds) {
4273 bindAddScreens(orderedScreenIds);
4274
4275 // If there are no screens, we need to have an empty screen
4276 if (orderedScreenIds.size() == 0) {
4277 mWorkspace.addExtraEmptyScreen();
4278 }
4279
4280 // Create the custom content page (this call updates mDefaultScreen which calls
4281 // setCurrentPage() so ensure that all pages are added before calling this).
4282 if (hasCustomContentToLeft()) {
4283 mWorkspace.createCustomContentContainer();
4284 populateCustomContentContainer();
4285 }
4286 }
4287
4288 @Override
4289 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
4290 // Log to disk
4291 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4292 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4293 TextUtils.join(", ", orderedScreenIds), true);
4294 int count = orderedScreenIds.size();
4295 for (int i = 0; i < count; i++) {
4296 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
4297 }
4298 }
4299
4300 private boolean shouldShowWeightWatcher() {
4301 String spKey = LauncherAppState.getSharedPreferencesKey();
4302 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4303 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
4304
4305 return show;
4306 }
4307
4308 private void toggleShowWeightWatcher() {
4309 String spKey = LauncherAppState.getSharedPreferencesKey();
4310 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4311 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4312
4313 show = !show;
4314
4315 SharedPreferences.Editor editor = sp.edit();
4316 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4317 editor.commit();
4318
4319 if (mWeightWatcher != null) {
4320 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4321 }
4322 }
4323
4324 public void bindAppsAdded(final ArrayList<Long> newScreens,
4325 final ArrayList<ItemInfo> addNotAnimated,
4326 final ArrayList<ItemInfo> addAnimated,
4327 final ArrayList<AppInfo> addedApps) {
4328 Runnable r = new Runnable() {
4329 public void run() {
4330 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
4331 }
4332 };
4333 if (waitUntilResume(r)) {
4334 return;
4335 }
4336
4337 // Add the new screens
4338 if (newScreens != null) {
4339 bindAddScreens(newScreens);
4340 }
4341
4342 // We add the items without animation on non-visible pages, and with
4343 // animations on the new page (which we will try and snap to).
4344 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
4345 bindItems(addNotAnimated, 0,
4346 addNotAnimated.size(), false);
4347 }
4348 if (addAnimated != null && !addAnimated.isEmpty()) {
4349 bindItems(addAnimated, 0,
4350 addAnimated.size(), true);
4351 }
4352
4353 // Remove the extra empty screen
4354 mWorkspace.removeExtraEmptyScreen(false, false);
4355
4356 if (!LauncherAppState.isDisableAllApps() &&
4357 addedApps != null && mAppsCustomizeContent != null) {
4358 mAppsCustomizeContent.addApps(addedApps);
4359 }
4360 }
4361
4362 /**
4363 * Bind the items start-end from the list.
4364 *
4365 * Implementation of the method from LauncherModel.Callbacks.
4366 */
4367 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4368 final boolean forceAnimateIcons) {
4369 Runnable r = new Runnable() {
4370 public void run() {
4371 bindItems(shortcuts, start, end, forceAnimateIcons);
4372 }
4373 };
4374 if (waitUntilResume(r)) {
4375 return;
4376 }
4377
4378 // Get the list of added shortcuts and intersect them with the set of shortcuts here
4379 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4380 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
4381 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
4382 Workspace workspace = mWorkspace;
4383 long newShortcutsScreenId = -1;
4384 for (int i = start; i < end; i++) {
4385 final ItemInfo item = shortcuts.get(i);
4386
4387 // Short circuit if we are loading dock items for a configuration which has no dock
4388 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4389 mHotseat == null) {
4390 continue;
4391 }
4392
4393 switch (item.itemType) {
4394 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4395 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
4396 ShortcutInfo info = (ShortcutInfo) item;
4397 View shortcut = createShortcut(info);
4398
4399 /*
4400 * TODO: FIX collision case
4401 */
4402 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4403 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4404 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
4405 View v = cl.getChildAt(item.cellX, item.cellY);
4406 Object tag = v.getTag();
4407 String desc = "Collision while binding workspace item: " + item
4408 + ". Collides with " + tag;
4409 if (LauncherAppState.isDogfoodBuild()) {
4410 throw (new RuntimeException(desc));
4411 } else {
4412 Log.d(TAG, desc);
4413 }
4414 }
4415 }
4416
4417 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4418 item.cellY, 1, 1);
4419 if (animateIcons) {
4420 // Animate all the applications up now
4421 shortcut.setAlpha(0f);
4422 shortcut.setScaleX(0f);
4423 shortcut.setScaleY(0f);
4424 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
4425 newShortcutsScreenId = item.screenId;
4426 }
4427 break;
4428 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
4429 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
4430 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
4431 (FolderInfo) item, mIconCache);
4432 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4433 item.cellY, 1, 1);
4434 break;
4435 default:
4436 throw new RuntimeException("Invalid Item Type");
4437 }
4438 }
4439
4440 if (animateIcons) {
4441 // Animate to the correct page
4442 if (newShortcutsScreenId > -1) {
4443 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
4444 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
4445 final Runnable startBounceAnimRunnable = new Runnable() {
4446 public void run() {
4447 anim.playTogether(bounceAnims);
4448 anim.start();
4449 }
4450 };
4451 if (newShortcutsScreenId != currentScreenId) {
4452 // We post the animation slightly delayed to prevent slowdowns
4453 // when we are loading right after we return to launcher.
4454 mWorkspace.postDelayed(new Runnable() {
4455 public void run() {
4456 if (mWorkspace != null) {
4457 mWorkspace.snapToPage(newScreenIndex);
4458 mWorkspace.postDelayed(startBounceAnimRunnable,
4459 NEW_APPS_ANIMATION_DELAY);
4460 }
4461 }
4462 }, NEW_APPS_PAGE_MOVE_DELAY);
4463 } else {
4464 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
4465 }
4466 }
4467 }
4468 workspace.requestLayout();
4469 }
4470
4471 /**
4472 * Implementation of the method from LauncherModel.Callbacks.
4473 */
4474 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
4475 Runnable r = new Runnable() {
4476 public void run() {
4477 bindFolders(folders);
4478 }
4479 };
4480 if (waitUntilResume(r)) {
4481 return;
4482 }
4483 sFolders.clear();
4484 sFolders.putAll(folders);
4485 }
4486
4487 /**
4488 * Add the views for a widget to the workspace.
4489 *
4490 * Implementation of the method from LauncherModel.Callbacks.
4491 */
4492 public void bindAppWidget(final LauncherAppWidgetInfo item) {
4493 Runnable r = new Runnable() {
4494 public void run() {
4495 bindAppWidget(item);
4496 }
4497 };
4498 if (waitUntilResume(r)) {
4499 return;
4500 }
4501
4502 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4503 if (DEBUG_WIDGETS) {
4504 Log.d(TAG, "bindAppWidget: " + item);
4505 }
4506 final Workspace workspace = mWorkspace;
4507
4508 AppWidgetProviderInfo appWidgetInfo;
4509 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4510 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4511
4512 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4513 if (appWidgetInfo == null) {
4514 if (DEBUG_WIDGETS) {
4515 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4516 + " belongs to component " + item.providerName
4517 + ", as the povider is null");
4518 }
4519 LauncherModel.deleteItemFromDatabase(this, item);
4520 return;
4521 }
4522 // Note: This assumes that the id remap broadcast is received before this step.
4523 // If that is not the case, the id remap will be ignored and user may see the
4524 // click to setup view.
4525 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4526 pendingInfo.spanX = item.spanX;
4527 pendingInfo.spanY = item.spanY;
4528 pendingInfo.minSpanX = item.minSpanX;
4529 pendingInfo.minSpanY = item.minSpanY;
4530 Bundle options =
4531 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4532
4533 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4534 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4535 newWidgetId, appWidgetInfo, options);
4536
4537 // TODO consider showing a permission dialog when the widget is clicked.
4538 if (!success) {
4539 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4540 if (DEBUG_WIDGETS) {
4541 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4542 + " belongs to component " + item.providerName
4543 + ", as the launcher is unable to bing a new widget id");
4544 }
4545 LauncherModel.deleteItemFromDatabase(this, item);
4546 return;
4547 }
4548
4549 item.appWidgetId = newWidgetId;
4550
4551 // If the widget has a configure activity, it is still needs to set it up, otherwise
4552 // the widget is ready to go.
4553 item.restoreStatus = (appWidgetInfo.configure == null)
4554 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4555 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4556
4557 LauncherModel.updateItemInDatabase(this, item);
4558 }
4559
4560 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4561 final int appWidgetId = item.appWidgetId;
4562 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4563 if (DEBUG_WIDGETS) {
4564 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidget🔵
4565 }
4566
4567 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4568 } else {
4569 appWidgetInfo = null;
4570 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4571 view.updateIcon(mIconCache);
4572 item.hostView = view;
4573 item.hostView.updateAppWidget(null);
4574 item.hostView.setOnClickListener(this);
4575 }
4576
4577 item.hostView.setTag(item);
4578 item.onBindAppWidget(this);
4579
4580 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
4581 item.cellY, item.spanX, item.spanY, false);
4582 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4583
4584 workspace.requestLayout();
4585
4586 if (DEBUG_WIDGETS) {
4587 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4588 + (SystemClock.uptimeMillis()-start) + "ms");
4589 }
4590 }
4591
4592 /**
4593 * Restores a pending widget.
4594 *
4595 * @param appWidgetId The app widget id
4596 * @param cellInfo The position on screen where to create the widget.
4597 */
4598 private void completeRestoreAppWidget(final int appWidgetId) {
4599 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4600 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4601 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4602 return;
4603 }
4604
4605 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
4606 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4607
4608 mWorkspace.reinflateWidgetsIfNecessary();
4609 LauncherModel.updateItemInDatabase(this, info);
4610 }
4611
4612 public void onPageBoundSynchronously(int page) {
4613 mSynchronouslyBoundPages.add(page);
4614 }
4615
4616 /**
4617 * Callback saying that there aren't any more items to bind.
4618 *
4619 * Implementation of the method from LauncherModel.Callbacks.
4620 */
4621 public void finishBindingItems(final boolean upgradePath) {
4622 Runnable r = new Runnable() {
4623 public void run() {
4624 finishBindingItems(upgradePath);
4625 }
4626 };
4627 if (waitUntilResume(r)) {
4628 return;
4629 }
4630 if (mSavedState != null) {
4631 if (!mWorkspace.hasFocus()) {
4632 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
4633 }
4634 mSavedState = null;
4635 }
4636
4637 mWorkspace.restoreInstanceStateForRemainingPages();
4638
4639 setWorkspaceLoading(false);
4640 sendLoadingCompleteBroadcastIfNecessary();
4641
4642 // If we received the result of any pending adds while the loader was running (e.g. the
4643 // widget configuration forced an orientation change), process them now.
4644 if (sPendingAddItem != null) {
4645 final long screenId = completeAdd(sPendingAddItem);
4646
4647 // TODO: this moves the user to the page where the pending item was added. Ideally,
4648 // the screen would be guaranteed to exist after bind, and the page would be set through
4649 // the workspace restore process.
4650 mWorkspace.post(new Runnable() {
4651 @Override
4652 public void run() {
4653 mWorkspace.snapToScreenId(screenId);
4654 }
4655 });
4656 sPendingAddItem = null;
4657 }
4658
4659 if (upgradePath) {
4660 mWorkspace.getUniqueComponents(true, null);
4661 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
4662 }
4663 PackageInstallerCompat.getInstance(this).onFinishBind();
4664 mModel.recheckRestoredItems(this);
4665 }
4666
4667 private void sendLoadingCompleteBroadcastIfNecessary() {
4668 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4669 String permission =
4670 getResources().getString(R.string.receive_first_load_broadcast_permission);
4671 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4672 sendBroadcast(intent, permission);
4673 SharedPreferences.Editor editor = mSharedPrefs.edit();
4674 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4675 editor.apply();
4676 }
4677 }
4678
4679 public boolean isAllAppsButtonRank(int rank) {
4680 if (mHotseat != null) {
4681 return mHotseat.isAllAppsButtonRank(rank);
4682 }
4683 return false;
4684 }
4685
4686 private boolean canRunNewAppsAnimation() {
4687 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4688 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4689 }
4690
4691 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4692 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4693 PropertyValuesHolder.ofFloat("alpha", 1f),
4694 PropertyValuesHolder.ofFloat("scaleX", 1f),
4695 PropertyValuesHolder.ofFloat("scaleY", 1f));
4696 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4697 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4698 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4699 return bounceAnim;
4700 }
4701
4702 public boolean useVerticalBarLayout() {
4703 return LauncherAppState.getInstance().getDynamicGrid().
4704 getDeviceProfile().isVerticalBarLayout();
4705 }
4706
4707 protected Rect getSearchBarBounds() {
4708 return LauncherAppState.getInstance().getDynamicGrid().
4709 getDeviceProfile().getSearchBarBounds();
4710 }
4711
4712 @Override
4713 public void bindSearchablesChanged() {
4714 boolean searchVisible = updateGlobalSearchIcon();
4715 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
4716 if (mSearchDropTargetBar != null) {
4717 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4718 }
4719 }
4720
4721 /**
4722 * Add the icons for all apps.
4723 *
4724 * Implementation of the method from LauncherModel.Callbacks.
4725 */
4726 public void bindAllApplications(final ArrayList<AppInfo> apps) {
4727 if (LauncherAppState.isDisableAllApps()) {
4728 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4729 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4730 getHotseat().addAllAppsFolder(mIconCache, apps,
4731 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4732 }
4733 mIntentsOnWorkspaceFromUpgradePath = null;
4734 }
4735 if (mAppsCustomizeContent != null) {
4736 mAppsCustomizeContent.onPackagesUpdated(
4737 LauncherModel.getSortedWidgetsAndShortcuts(this));
4738 }
4739 } else {
4740 if (mAppsCustomizeContent != null) {
4741 mAppsCustomizeContent.setApps(apps);
4742 mAppsCustomizeContent.onPackagesUpdated(
4743 LauncherModel.getSortedWidgetsAndShortcuts(this));
4744 }
4745 }
4746 }
4747
4748 /**
4749 * A package was updated.
4750 *
4751 * Implementation of the method from LauncherModel.Callbacks.
4752 */
4753 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
4754 Runnable r = new Runnable() {
4755 public void run() {
4756 bindAppsUpdated(apps);
4757 }
4758 };
4759 if (waitUntilResume(r)) {
4760 return;
4761 }
4762
4763 if (mWorkspace != null) {
4764 mWorkspace.updateShortcutsAndWidgets(apps);
4765 }
4766
4767 if (!LauncherAppState.isDisableAllApps() &&
4768 mAppsCustomizeContent != null) {
4769 mAppsCustomizeContent.updateApps(apps);
4770 }
4771 }
4772
4773 /**
4774 * Packages were restored
4775 */
4776 public void bindAppsRestored(final ArrayList<AppInfo> apps) {
4777 Runnable r = new Runnable() {
4778 public void run() {
4779 bindAppsRestored(apps);
4780 }
4781 };
4782 if (waitUntilResume(r)) {
4783 return;
4784 }
4785
4786 if (mWorkspace != null) {
4787 mWorkspace.updateShortcutsAndWidgets(apps);
4788 }
4789 }
4790
4791 /**
4792 * Update the state of a package, typically related to install state.
4793 *
4794 * Implementation of the method from LauncherModel.Callbacks.
4795 */
4796 @Override
4797 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
4798 if (mWorkspace != null) {
4799 mWorkspace.updatePackageState(installInfo);
4800 }
4801 }
4802
4803 /**
4804 * Update the label and icon of all the icons in a package
4805 *
4806 * Implementation of the method from LauncherModel.Callbacks.
4807 */
4808 @Override
4809 public void updatePackageBadge(String packageName) {
4810 if (mWorkspace != null) {
4811 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4812 }
4813 }
4814
4815 /**
4816 * A package was uninstalled. We take both the super set of packageNames
4817 * in addition to specific applications to remove, the reason being that
4818 * this can be called when a package is updated as well. In that scenario,
4819 * we only remove specific components from the workspace, where as
4820 * package-removal should clear all items by package name.
4821 *
4822 * Implementation of the method from LauncherModel.Callbacks.
4823 */
4824 public void bindComponentsRemoved(final ArrayList<String> packageNames,
4825 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
4826 Runnable r = new Runnable() {
4827 public void run() {
4828 bindComponentsRemoved(packageNames, appInfos, user);
4829 }
4830 };
4831 if (waitUntilResume(r)) {
4832 return;
4833 }
4834
4835 if (!packageNames.isEmpty()) {
4836 mWorkspace.removeItemsByPackageName(packageNames, user);
4837 }
4838 if (!appInfos.isEmpty()) {
4839 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
4840 }
4841
4842 // Notify the drag controller
4843 mDragController.onAppsRemoved(packageNames, appInfos);
4844
4845 // Update AllApps
4846 if (!LauncherAppState.isDisableAllApps() &&
4847 mAppsCustomizeContent != null) {
4848 mAppsCustomizeContent.removeApps(appInfos);
4849 }
4850 }
4851
4852 /**
4853 * A number of packages were updated.
4854 */
4855 private ArrayList<Object> mWidgetsAndShortcuts;
4856 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
4857 public void run() {
4858 bindPackagesUpdated(mWidgetsAndShortcuts);
4859 mWidgetsAndShortcuts = null;
4860 }
4861 };
4862 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4863 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4864 mWidgetsAndShortcuts = widgetsAndShortcuts;
4865 return;
4866 }
4867
4868 // Update the widgets pane
4869 if (mAppsCustomizeContent != null) {
4870 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
4871 }
4872 }
4873
4874 private int mapConfigurationOriActivityInfoOri(int configOri) {
4875 final Display d = getWindowManager().getDefaultDisplay();
4876 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4877 switch (d.getRotation()) {
4878 case Surface.ROTATION_0:
4879 case Surface.ROTATION_180:
4880 // We are currently in the same basic orientation as the natural orientation
4881 naturalOri = configOri;
4882 break;
4883 case Surface.ROTATION_90:
4884 case Surface.ROTATION_270:
4885 // We are currently in the other basic orientation to the natural orientation
4886 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4887 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4888 break;
4889 }
4890
4891 int[] oriMap = {
4892 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4893 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4894 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4895 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4896 };
4897 // Since the map starts at portrait, we need to offset if this device's natural orientation
4898 // is landscape.
4899 int indexOffset = 0;
4900 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4901 indexOffset = 1;
4902 }
4903 return oriMap[(d.getRotation() + indexOffset) % 4];
4904 }
4905
4906 public boolean isRotationEnabled() {
4907 boolean enableRotation = sForceEnableRotation ||
4908 getResources().getBoolean(R.bool.allow_rotation);
4909 return enableRotation;
4910 }
4911 public void lockScreenOrientation() {
4912 if (isRotationEnabled()) {
4913 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4914 .getConfiguration().orientation));
4915 }
4916 }
4917 public void unlockScreenOrientation(boolean immediate) {
4918 if (isRotationEnabled()) {
4919 if (immediate) {
4920 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4921 } else {
4922 mHandler.postDelayed(new Runnable() {
4923 public void run() {
4924 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4925 }
4926 }, mRestoreScreenOrientationDelay);
4927 }
4928 }
4929 }
4930
4931 /**
4932 * Called when the SearchBar hint should be changed.
4933 *
4934 * @param hint the hint to be displayed in the search bar.
4935 */
4936 protected void onSearchBarHintChanged(String hint) {
4937
4938 }
4939
4940 protected boolean isLauncherPreinstalled() {
4941 PackageManager pm = getPackageManager();
4942 try {
4943 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4944 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4945 return true;
4946 } else {
4947 return false;
4948 }
4949 } catch (NameNotFoundException e) {
4950 e.printStackTrace();
4951 return false;
4952 }
4953 }
4954
4955 <<<<<<< GitAnalyzerPlus_ours
4956 /**
4957 * This method indicates whether or not we should suggest default wallpaper dimensions
4958 * when our wallpaper cropper was not yet used to set a wallpaper.
4959 */
4960 protected boolean overrideWallpaperDimensions() {
4961 return true;
4962 }
4963
4964 protected boolean shouldClingFocusHotseatApp() {
4965 return false;
4966 }
4967 ||||||| GitAnalyzerPlus_base
4968 mLauncherClings.dismissFirstRunCling(v);
4969 }
4970 public void dismissMigrationClingCopyApps(View v) {
4971 mLauncherClings.dismissMigrationClingCopyApps(v);
4972 }
4973 public void dismissMigrationClingUseDefault(View v) {
4974 mLauncherClings.dismissMigrationClingUseDefault(v);
4975 }
4976 public void dismissMigrationWorkspaceCling(View v) {
4977 mLauncherClings.dismissMigrationWorkspaceCling(v);
4978 }
4979 public void dismissWorkspaceCling(View v) {
4980 mLauncherClings.dismissWorkspaceCling(v);
4981 }
4982 public void dismissFolderCling(View v) {
4983 mLauncherClings.dismissFolderCling(v);
4984 }
4985
4986 private boolean shouldRunFirstRunActivity() {
4987 return !ActivityManager.isRunningInTestHarness();
4988 }
4989
4990 public void showFirstRunActivity() {
4991 if (shouldRunFirstRunActivity() && hasFirstRunActivity()
4992 && !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false)) {
4993 Intent firstRunIntent = getFirstRunActivity();
4994 if (firstRunIntent != null) {
4995 startActivity(firstRunIntent);
4996 markFirstRunActivityShown();
4997 }
4998 }
4999 }
5000
5001 private void markFirstRunActivityShown() {
5002 SharedPreferences.Editor editor = mSharedPrefs.edit();
5003 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
5004 editor.apply();
5005 }
5006
5007 void showWorkspaceSearchAndHotseat() {
5008 mWorkspace.setAlpha(1f);
5009 mHotseat.setAlpha(1f);
5010 mPageIndicators.setAlpha(1f);
5011 mSearchDropTargetBar.showSearchBar(false);
5012 }
5013
5014 void hideWorkspaceSearchAndHotseat() {
5015 mWorkspace.setAlpha(0f);
5016 mHotseat.setAlpha(0f);
5017 mPageIndicators.setAlpha(0f);
5018 mSearchDropTargetBar.hideSearchBar(false);
5019 }
5020
5021
5022 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
5023 ResolveInfo ri = getPackageManager().resolveActivity(appLaunchIntent, 0);
5024 if (ri == null) {
5025 return null;
5026 }
5027 return new AppInfo(getPackageManager(), ri, mIconCache, null);
5028 }
5029
5030 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5031 Bitmap icon) {
5032 return new ShortcutInfo(shortcutIntent, caption, icon);
5033 }
5034
5035 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5036 dragView.setTag(dragInfo);
5037 mWorkspace.onDragStartedWithItem(dragView);
5038 mWorkspace.beginDragShared(dragView, source);
5039 }
5040
5041 /**
5042 * Prints out out state for debugging.
5043 */
5044 public void dumpState() {
5045 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
5046 Log.d(TAG, "mSavedState=" + mSavedState);
5047 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5048 Log.d(TAG, "mRestoring=" + mRestoring);
5049 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5050 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
5051 Log.d(TAG, "sFolders.size=" + sFolders.size());
5052 mModel.dumpState();
5053
5054 if (mAppsCustomizeContent != null) {
5055 mAppsCustomizeContent.dumpState();
5056 }
5057 Log.d(TAG, "END launcher3 dump state");
5058 }
5059
5060 @Override
5061 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5062 super.dump(prefix, fd, writer, args);
5063 synchronized (sDumpLogs) {
5064 writer.println(" ");
5065 writer.println("Debug logs: ");
5066 for (int i = 0; i < sDumpLogs.size(); i++) {
5067 writer.println(" " + sDumpLogs.get(i));
5068 }
5069 }
5070 }
5071
5072 public static void dumpDebugLogsToConsole() {
5073 if (DEBUG_DUMP_LOG) {
5074 synchronized (sDumpLogs) {
5075 Log.d(TAG, "");
5076 Log.d(TAG, "*********************");
5077 Log.d(TAG, "Launcher debug logs: ");
5078 for (int i = 0; i < sDumpLogs.size(); i++) {
5079 Log.d(TAG, " " + sDumpLogs.get(i));
5080 }
5081 Log.d(TAG, "*********************");
5082 Log.d(TAG, "");
5083 }
5084 }
5085 }
5086
5087 public static void addDumpLog(String tag, String log, boolean debugLog) {
5088 addDumpLog(tag, log, null, debugLog);
5089 }
5090
5091 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
5092 if (debugLog) {
5093 if (e != null) {
5094 Log.d(tag, log, e);
5095 } else {
5096 Log.d(tag, log);
5097 }
5098 }
5099 if (DEBUG_DUMP_LOG) {
5100 sDateStamp.setTime(System.currentTimeMillis());
5101 synchronized (sDumpLogs) {
5102 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5103 + (e == null ? "" : (", Exception: " + e)));
5104 }
5105 }
5106 }
5107
5108 public void dumpLogsToLocalData() {
5109 if (DEBUG_DUMP_LOG) {
5110 new AsyncTask<Void, Void, Void>() {
5111 public Void doInBackground(Void ... args) {
5112 boolean success = false;
5113 sDateStamp.setTime(sRunStart);
5114 String FILENAME = sDateStamp.getMonth() + "-"
5115 + sDateStamp.getDay() + "_"
5116 + sDateStamp.getHours() + "-"
5117 + sDateStamp.getMinutes() + "_"
5118 + sDateStamp.getSeconds() + ".txt";
5119
5120 FileOutputStream fos = null;
5121 File outFile = null;
5122 try {
5123 outFile = new File(getFilesDir(), FILENAME);
5124 outFile.createNewFile();
5125 fos = new FileOutputStream(outFile);
5126 } catch (Exception e) {
5127 e.printStackTrace();
5128 }
5129 if (fos != null) {
5130 PrintWriter writer = new PrintWriter(fos);
5131
5132 writer.println(" ");
5133 writer.println("Debug logs: ");
5134 synchronized (sDumpLogs) {
5135 for (int i = 0; i < sDumpLogs.size(); i++) {
5136 writer.println(" " + sDumpLogs.get(i));
5137 }
5138 }
5139 writer.close();
5140 }
5141 try {
5142 if (fos != null) {
5143 fos.close();
5144 success = true;
5145 }
5146 } catch (IOException e) {
5147 e.printStackTrace();
5148 }
5149 return null;
5150 }
5151 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
5152 }
5153 }
5154 }
5155
5156 interface LauncherTransitionable {
5157 View getContent();
5158 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
5159 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
5160 void onLauncherTransitionStep(Launcher l, float t);
5161 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
5162 }
5163
5164 interface DebugIntents {
5165 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5166 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
5167 }
5168 =======
5169 >>>>>>> GitAnalyzerPlus_theirs
5170 protected String getFirstRunClingSearchBarHint() {
5171 return "";
5172 }
5173 protected String getFirstRunCustomContentHint() {
5174 return "";
5175 }
5176 protected int getFirstRunFocusedHotseatAppDrawableId() {
5177 return -1;
5178 }
5179 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
5180 return null;
5181 }
5182 protected int getFirstRunFocusedHotseatAppRank() {
5183 return -1;
5184 }
5185 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
5186 return "";
5187 }
5188 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
5189 return "";
5190 }
5191
5192 /**
5193 * To be overridden by subclasses to indicate that there is an activity to launch
5194 * before showing the standard launcher experience.
5195 */
5196 protected boolean hasFirstRunActivity() {
5197 return false;
5198 }
5199
5200 /**
5201 * To be overridden by subclasses to launch any first run activity
5202 */
5203 protected Intent getFirstRunActivity() {
5204 return null;
5205 }
5206
5207 private boolean shouldRunFirstRunActivity() {
5208 return !ActivityManager.isRunningInTestHarness() &&
5209 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5210 }
5211
5212 protected boolean hasRunFirstRunActivity() {
5213 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5214 }
5215
5216 public boolean showFirstRunActivity() {
5217 if (shouldRunFirstRunActivity() &&
5218 hasFirstRunActivity()) {
5219 Intent firstRunIntent = getFirstRunActivity();
5220 if (firstRunIntent != null) {
5221 startActivity(firstRunIntent);
5222 markFirstRunActivityShown();
5223 return true;
5224 }
5225 }
5226 return false;
5227 }
5228
5229 private void markFirstRunActivityShown() {
5230 SharedPreferences.Editor editor = mSharedPrefs.edit();
5231 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
5232 editor.apply();
5233 }
5234
5235 /**
5236 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
5237 * screen that must be displayed and dismissed.
5238 */
5239 protected boolean hasDismissableIntroScreen() {
5240 return false;
5241 }
5242
5243 /**
5244 * Full screen intro screen to be shown and dismissed before the launcher can be used.
5245 */
5246 protected View getIntroScreen() {
5247 return null;
5248 }
5249
5250 /**
5251 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
5252 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
5253 */
5254 private boolean shouldShowIntroScreen() {
5255 return hasDismissableIntroScreen() &&
5256 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
5257 }
5258
5259 protected void showIntroScreen() {
5260 View introScreen = getIntroScreen();
5261 changeWallpaperVisiblity(false);
5262 if (introScreen != null) {
5263 mDragLayer.showOverlayView(introScreen);
5264 }
5265 }
5266
5267 public void dismissIntroScreen() {
5268 markIntroScreenDismissed();
5269 if (showFirstRunActivity()) {
5270 // We delay hiding the intro view until the first run activity is showing. This
5271 // avoids a blip.
5272 mWorkspace.postDelayed(new Runnable() {
5273 @Override
5274 public void run() {
5275 mDragLayer.dismissOverlayView();
5276 showFirstRunClings();
5277 }
5278 }, ACTIVITY_START_DELAY);
5279 } else {
5280 mDragLayer.dismissOverlayView();
5281 showFirstRunClings();
5282 }
5283 changeWallpaperVisiblity(true);
5284 }
5285
5286 private void markIntroScreenDismissed() {
5287 SharedPreferences.Editor editor = mSharedPrefs.edit();
5288 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5289 editor.apply();
5290 }
5291
5292 private void showFirstRunClings() {
5293 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
5294 // on the device, then we always show the first run cling experience (or if there is no
5295 // launcher2). Otherwise, we prompt the user upon started for migration
5296 LauncherClings launcherClings = new LauncherClings(this);
5297 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5298 if (mModel.canMigrateFromOldLauncherDb(this)) {
5299 launcherClings.showMigrationCling();
5300 } else {
5301 launcherClings.showLongPressCling(true);
5302 }
5303 }
5304 }
5305
5306 void showWorkspaceSearchAndHotseat() {
5307 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5308 if (mHotseat != null) mHotseat.setAlpha(1f);
5309 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5310 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
5311 }
5312
5313 void hideWorkspaceSearchAndHotseat() {
5314 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5315 if (mHotseat != null) mHotseat.setAlpha(0f);
5316 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5317 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
5318 }
5319
5320 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
5321 // Called from search suggestion, not supported in other profiles.
5322 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5323 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5324 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5325 myUser);
5326 if (activityInfo == null) {
5327 return null;
5328 }
5329 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
5330 }
5331
5332 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5333 Bitmap icon) {
5334 // Called from search suggestion, not supported in other profiles.
5335 return createShortcutDragInfo(shortcutIntent, caption, icon,
5336 UserHandleCompat.myUserHandle());
5337 }
5338
5339 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5340 Bitmap icon, UserHandleCompat user) {
5341 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
5342 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
5343 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
5344 }
5345
5346 protected void moveWorkspaceToDefaultScreen() {
5347 mWorkspace.moveToDefaultScreen(false);
5348 }
5349
5350 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5351 dragView.setTag(dragInfo);
5352 mWorkspace.onExternalDragStartedWithItem(dragView);
5353 mWorkspace.beginExternalDragShared(dragView, source);
5354 }
5355
5356 @Override
5357 public void onPageSwitch(View newPage, int newPageIndex) {
5358 }
5359
5360 /**
5361 * Prints out out state for debugging.
5362 */
5363 public void dumpState() {
5364 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
5365 Log.d(TAG, "mSavedState=" + mSavedState);
5366 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5367 Log.d(TAG, "mRestoring=" + mRestoring);
5368 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5369 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
5370 Log.d(TAG, "sFolders.size=" + sFolders.size());
5371 mModel.dumpState();
5372
5373 if (mAppsCustomizeContent != null) {
5374 mAppsCustomizeContent.dumpState();
5375 }
5376 Log.d(TAG, "END launcher3 dump state");
5377 }
5378
5379 @Override
5380 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5381 super.dump(prefix, fd, writer, args);
5382 synchronized (sDumpLogs) {
5383 writer.println(" ");
5384 writer.println("Debug logs: ");
5385 for (int i = 0; i < sDumpLogs.size(); i++) {
5386 writer.println(" " + sDumpLogs.get(i));
5387 }
5388 }
5389 }
5390
5391 public static void dumpDebugLogsToConsole() {
5392 if (DEBUG_DUMP_LOG) {
5393 synchronized (sDumpLogs) {
5394 Log.d(TAG, "");
5395 Log.d(TAG, "*********************");
5396 Log.d(TAG, "Launcher debug logs: ");
5397 for (int i = 0; i < sDumpLogs.size(); i++) {
5398 Log.d(TAG, " " + sDumpLogs.get(i));
5399 }
5400 Log.d(TAG, "*********************");
5401 Log.d(TAG, "");
5402 }
5403 }
5404 }
5405
5406 public static void addDumpLog(String tag, String log, boolean debugLog) {
5407 addDumpLog(tag, log, null, debugLog);
5408 }
5409
5410 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
5411 if (debugLog) {
5412 if (e != null) {
5413 Log.d(tag, log, e);
5414 } else {
5415 Log.d(tag, log);
5416 }
5417 }
5418 if (DEBUG_DUMP_LOG) {
5419 sDateStamp.setTime(System.currentTimeMillis());
5420 synchronized (sDumpLogs) {
5421 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5422 + (e == null ? "" : (", Exception: " + e)));
5423 }
5424 }
5425 }
5426
5427 public void dumpLogsToLocalData() {
5428 if (DEBUG_DUMP_LOG) {
5429 new AsyncTask<Void, Void, Void>() {
5430 public Void doInBackground(Void ... args) {
5431 boolean success = false;
5432 sDateStamp.setTime(sRunStart);
5433 String FILENAME = sDateStamp.getMonth() + "-"
5434 + sDateStamp.getDay() + "_"
5435 + sDateStamp.getHours() + "-"
5436 + sDateStamp.getMinutes() + "_"
5437 + sDateStamp.getSeconds() + ".txt";
5438
5439 FileOutputStream fos = null;
5440 File outFile = null;
5441 try {
5442 outFile = new File(getFilesDir(), FILENAME);
5443 outFile.createNewFile();
5444 fos = new FileOutputStream(outFile);
5445 } catch (Exception e) {
5446 e.printStackTrace();
5447 }
5448 if (fos != null) {
5449 PrintWriter writer = new PrintWriter(fos);
5450
5451 writer.println(" ");
5452 writer.println("Debug logs: ");
5453 synchronized (sDumpLogs) {
5454 for (int i = 0; i < sDumpLogs.size(); i++) {
5455 writer.println(" " + sDumpLogs.get(i));
5456 }
5457 }
5458 writer.close();
5459 }
5460 try {
5461 if (fos != null) {
5462 fos.close();
5463 success = true;
5464 }
5465 } catch (IOException e) {
5466 e.printStackTrace();
5467 }
5468 return null;
5469 }
5470 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
5471 }
5472 }
5473 }
5474
5475 interface LauncherTransitionable {
5476 View getContent();
5477 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
5478 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
5479 void onLauncherTransitionStep(Launcher l, float t);
5480 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
5481 }
5482
5483 interface DebugIntents {
5484 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5485 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
5486 } |
1
2 /*
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.android.launcher3;
19
20 import android.animation.Animator;
21 import android.animation.AnimatorListenerAdapter;
22 import android.animation.AnimatorSet;
23 import android.animation.ObjectAnimator;
24 import android.animation.PropertyValuesHolder;
25 import android.animation.TimeInterpolator;
26 import android.animation.ValueAnimator;
27 import android.annotation.TargetApi;
28 import android.app.Activity;
29 import android.app.ActivityManager;
30 import android.app.ActivityOptions;
31 import android.app.AlertDialog;
32 import android.app.SearchManager;
33 import android.appwidget.AppWidgetHostView;
34 import android.appwidget.AppWidgetManager;
35 import android.appwidget.AppWidgetProviderInfo;
36 import android.content.ActivityNotFoundException;
37 import android.content.BroadcastReceiver;
38 import android.content.ComponentCallbacks2;
39 import android.content.ComponentName;
40 import android.content.ContentResolver;
41 import android.content.Context;
42 import android.content.DialogInterface;
43 import android.content.Intent;
44 import android.content.IntentFilter;
45 import android.content.SharedPreferences;
46 import android.content.pm.ActivityInfo;
47 import android.content.pm.ApplicationInfo;
48 import android.content.pm.PackageManager;
49 import android.content.pm.PackageManager.NameNotFoundException;
50 import android.content.res.Configuration;
51 import android.content.res.Resources;
52 import android.database.ContentObserver;
53 import android.graphics.Bitmap;
54 import android.graphics.Canvas;
55 import android.graphics.Color;
56 import android.graphics.Point;
57 import android.graphics.PorterDuff;
58 import android.graphics.Rect;
59 import android.graphics.drawable.Drawable;
60 import android.net.Uri;
61 import android.os.AsyncTask;
62 import android.os.Build;
63 import android.os.Bundle;
64 import android.os.Environment;
65 import android.os.Handler;
66 import android.os.Message;
67 import android.os.StrictMode;
68 import android.os.SystemClock;
69 import android.speech.RecognizerIntent;
70 import android.text.Selection;
71 import android.text.SpannableStringBuilder;
72 import android.text.TextUtils;
73 import android.text.method.TextKeyListener;
74 import android.util.DisplayMetrics;
75 import android.util.Log;
76 import android.view.ContextThemeWrapper;
77 import android.view.Display;
78 import android.view.Gravity;
79 import android.view.HapticFeedbackConstants;
80 import android.view.KeyEvent;
81 import android.view.LayoutInflater;
82 import android.view.Menu;
83 import android.view.MotionEvent;
84 import android.view.Surface;
85 import android.view.View;
86 import android.view.View.OnClickListener;
87 import android.view.View.OnLongClickListener;
88 import android.view.ViewAnimationUtils;
89 import android.view.ViewGroup;
90 import android.view.ViewTreeObserver;
91 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
92 import android.view.Window;
93 import android.view.WindowManager;
94 import android.view.accessibility.AccessibilityEvent;
95 import android.view.animation.AccelerateInterpolator;
96 import android.view.animation.DecelerateInterpolator;
97 import android.view.animation.Interpolator;
98 import android.view.inputmethod.InputMethodManager;
99 import android.widget.Advanceable;
100 import android.widget.FrameLayout;
101 import android.widget.ImageView;
102 import android.widget.TextView;
103 import android.widget.Toast;
104
105 import com.android.launcher3.DropTarget.DragObject;
106 import com.android.launcher3.PagedView.PageSwitchListener;
107 import com.android.launcher3.compat.AppWidgetManagerCompat;
108 import com.android.launcher3.compat.LauncherActivityInfoCompat;
109 import com.android.launcher3.compat.LauncherAppsCompat;
110 import com.android.launcher3.compat.PackageInstallerCompat;
111 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
112 import com.android.launcher3.compat.UserHandleCompat;
113 import com.android.launcher3.compat.UserManagerCompat;
114
115 import java.io.DataInputStream;
116 import java.io.DataOutputStream;
117 import java.io.File;
118 import java.io.FileDescriptor;
119 import java.io.FileNotFoundException;
120 import java.io.FileOutputStream;
121 import java.io.IOException;
122 import java.io.PrintWriter;
123 import java.lang.reflect.Field;
124 import java.lang.reflect.InvocationTargetException;
125 import java.lang.reflect.Method;
126 import java.text.DateFormat;
127 import java.util.ArrayList;
128 import java.util.Collection;
129 import java.util.Date;
130 import java.util.HashMap;
131 import java.util.List;
132 import java.util.concurrent.atomic.AtomicInteger;
133
134
135 /**
136 * Default launcher application.
137 */
138 public class Launcher extends Activity
139 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
140 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
141 static final String TAG = "Launcher";
142 static final boolean LOGD = false;
143
144 static final boolean PROFILE_STARTUP = false;
145 static final boolean DEBUG_WIDGETS = false;
146 static final boolean DEBUG_STRICT_MODE = false;
147 static final boolean DEBUG_RESUME_TIME = false;
148 static final boolean DEBUG_DUMP_LOG = false;
149
150 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
151
152 private static final int REQUEST_CREATE_SHORTCUT = 1;
153 private static final int REQUEST_CREATE_APPWIDGET = 5;
154 private static final int REQUEST_PICK_SHORTCUT = 7;
155 private static final int REQUEST_PICK_APPWIDGET = 9;
156 private static final int REQUEST_PICK_WALLPAPER = 10;
157
158 private static final int REQUEST_BIND_APPWIDGET = 11;
159 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
160
161 /**
162 * IntentStarter uses request codes starting with this. This must be greater than all activity
163 * request codes used internally.
164 */
165 protected static final int REQUEST_LAST = 100;
166
167 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
168
169 static final int SCREEN_COUNT = 5;
170 static final int DEFAULT_SCREEN = 2;
171
172 private static final String PREFERENCES = "launcher.preferences";
173 // To turn on these properties, type
174 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
175 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
176 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
177 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
178
179 // The Intent extra that defines whether to ignore the launch animation
180 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
181 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
182
183 // Type: int
184 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
185 // Type: int
186 private static final String RUNTIME_STATE = "launcher.state";
187 // Type: int
188 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
189 // Type: int
190 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
191 // Type: int
192 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
193 // Type: int
194 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
195 // Type: boolean
196 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
197 // Type: long
198 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
199 // Type: int
200 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
201 // Type: int
202 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
203 // Type: parcelable
204 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
205 // Type: parcelable
206 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
207 // Type: int[]
208 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
209
210 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
211 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
212
213 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
214 static final String ACTION_FIRST_LOAD_COMPLETE =
215 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
216
217 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
218 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
219 "com.android.launcher.toolbar_search_icon";
220 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
221 "com.android.launcher.toolbar_voice_search_icon";
222
223 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
224 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
225
226 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
227
228 /** The different states that Launcher can be in. */
229 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };;
230 private State mState = State.WORKSPACE;
231 private AnimatorSet mStateAnimation;
232
233 private boolean mIsSafeModeEnabled;
234
235 static final int APPWIDGET_HOST_ID = 1024;
236 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
237 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
238 private static final int ACTIVITY_START_DELAY = 1000;
239
240 private static final Object sLock = new Object();
241 private static int sScreen = DEFAULT_SCREEN;
242
243 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
244 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
245
246 // How long to wait before the new-shortcut animation automatically pans the workspace
247 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
248 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
249 private static int NEW_APPS_ANIMATION_DELAY = 500;
250 private static final int SINGLE_FRAME_DELAY = 16;
251
252 private final BroadcastReceiver mCloseSystemDialogsReceiver
253 = new CloseSystemDialogsIntentReceiver();
254 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
255
256 private LayoutInflater mInflater;
257
258 private Workspace mWorkspace;
259 private View mLauncherView;
260 private View mPageIndicators;
261 private DragLayer mDragLayer;
262 private DragController mDragController;
263 private View mWeightWatcher;
264 private LauncherClings mLauncherClings;
265
266 private AppWidgetManagerCompat mAppWidgetManager;
267 private LauncherAppWidgetHost mAppWidgetHost;
268
269 private ItemInfo mPendingAddInfo = new ItemInfo();
270 private AppWidgetProviderInfo mPendingAddWidgetInfo;
271 private int mPendingAddWidgetId = -1;
272
273 private int[] mTmpAddItemCellCoordinates = new int[2];
274
275 private FolderInfo mFolderInfo;
276
277 private Hotseat mHotseat;
278 private ViewGroup mOverviewPanel;
279
280 private View mAllAppsButton;
281
282 private SearchDropTargetBar mSearchDropTargetBar;
283 private AppsCustomizeTabHost mAppsCustomizeTabHost;
284 private AppsCustomizePagedView mAppsCustomizeContent;
285 private boolean mAutoAdvanceRunning = false;
286 private View mQsb;
287
288 private Bundle mSavedState;
289 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
290 // scroll issues (because the workspace may not have been measured yet) and extra work.
291 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
292 private State mOnResumeState = State.NONE;
293
294 private SpannableStringBuilder mDefaultKeySsb = null;
295
296 private boolean mWorkspaceLoading = true;
297
298 private boolean mPaused = true;
299 private boolean mRestoring;
300 private boolean mWaitingForResult;
301 private boolean mOnResumeNeedsLoad;
302
303 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
304 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
305
306 private Bundle mSavedInstanceState;
307
308 private LauncherModel mModel;
309 private IconCache mIconCache;
310 private boolean mUserPresent = true;
311 private boolean mVisible = false;
312 private boolean mHasFocus = false;
313 private boolean mAttached = false;
314
315 private static LocaleConfiguration sLocaleConfiguration = null;
316
317 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
318
319 private View.OnTouchListener mHapticFeedbackTouchListener;
320
321 // Related to the auto-advancing of widgets
322 private final int ADVANCE_MSG = 1;
323 private final int mAdvanceInterval = 20000;
324 private final int mAdvanceStagger = 250;
325 private long mAutoAdvanceSentTime;
326 private long mAutoAdvanceTimeLeft = -1;
327 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
328 new HashMap<View, AppWidgetProviderInfo>();
329
330 // Determines how long to wait after a rotation before restoring the screen orientation to
331 // match the sensor state.
332 private final int mRestoreScreenOrientationDelay = 500;
333
334 // External icons saved in case of resource changes, orientation, etc.
335 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
336 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
337
338 private Drawable mWorkspaceBackgroundDrawable;
339
340 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
341 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
342
343 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
344 static Date sDateStamp = new Date();
345 static DateFormat sDateFormat =
346 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
347 static long sRunStart = System.currentTimeMillis();
348 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
349
350 // We only want to get the SharedPreferences once since it does an FS stat each time we get
351 // it from the context.
352 private SharedPreferences mSharedPrefs;
353
354 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
355
356 // Holds the page that we need to animate to, and the icon views that we need to animate up
357 // when we scroll to that page on resume.
358 private ImageView mFolderIconImageView;
359 private Bitmap mFolderIconBitmap;
360 private Canvas mFolderIconCanvas;
361 private Rect mRectForFolderAnimation = new Rect();
362
363 private BubbleTextView mWaitingForResume;
364
365 private Runnable mBuildLayersRunnable = new Runnable() {
366 public void run() {
367 if (mWorkspace != null) {
368 mWorkspace.buildPageHardwareLayers();
369 }
370 }
371 };
372
373 private static PendingAddArguments sPendingAddItem;
374
375 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
376
377 private static class PendingAddArguments {
378 int requestCode;
379 Intent intent;
380 long container;
381 long screenId;
382 int cellX;
383 int cellY;
384 int appWidgetId;
385 }
386
387 private Stats mStats;
388
389 FocusIndicatorView mFocusHandler;
390
391 static boolean isPropertyEnabled(String propertyName) {
392 return Log.isLoggable(propertyName, Log.VERBOSE);
393 }
394
395 @Override
396 protected void onCreate(Bundle savedInstanceState) {
397 if (DEBUG_STRICT_MODE) {
398 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
399 .detectDiskReads()
400 .detectDiskWrites()
401 .detectNetwork() // or .detectAll() for all detectable problems
402 .penaltyLog()
403 .build());
404 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
405 .detectLeakedSqlLiteObjects()
406 .detectLeakedClosableObjects()
407 .penaltyLog()
408 .penaltyDeath()
409 .build());
410 }
411
412 super.onCreate(savedInstanceState);
413
414 LauncherAppState.setApplicationContext(getApplicationContext());
415 LauncherAppState app = LauncherAppState.getInstance();
416 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
417 // Determine the dynamic grid properties
418 Point smallestSize = new Point();
419 Point largestSize = new Point();
420 Point realSize = new Point();
421 Display display = getWindowManager().getDefaultDisplay();
422 display.getCurrentSizeRange(smallestSize, largestSize);
423 display.getRealSize(realSize);
424 DisplayMetrics dm = new DisplayMetrics();
425 display.getMetrics(dm);
426
427 // Lazy-initialize the dynamic grid
428 DeviceProfile grid = app.initDynamicGrid(this,
429 Math.min(smallestSize.x, smallestSize.y),
430 Math.min(largestSize.x, largestSize.y),
431 realSize.x, realSize.y,
432 dm.widthPixels, dm.heightPixels);
433
434 // the LauncherApplication should call this, but in case of Instrumentation it might not be prese🔵
435 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
436 Context.MODE_PRIVATE);
437 mIsSafeModeEnabled = getPackageManager().isSafeMode();
438 mModel = app.setLauncher(this);
439 mIconCache = app.getIconCache();
440 mIconCache.flushInvalidIcons(grid);
441 mDragController = new DragController(this);
442 mLauncherClings = new LauncherClings(this);
443 mInflater = getLayoutInflater();
444
445 mStats = new Stats(this);
446
447 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
448
449 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
450 mAppWidgetHost.startListening();
451
452 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
453 // this also ensures that any synchronous binding below doesn't re-trigger another
454 // LauncherModel load.
455 mPaused = false;
456
457 if (PROFILE_STARTUP) {
458 android.os.Debug.startMethodTracing(
459 Environment.getExternalStorageDirectory() + "/launcher");
460 }
461
462 checkForLocaleChange();
463 setContentView(R.layout.launcher);
464
465 setupViews();
466 grid.layout(this);
467
468 registerContentObservers();
469
470 lockAllApps();
471
472 mSavedState = savedInstanceState;
473 restoreState(mSavedState);
474
475 if (PROFILE_STARTUP) {
476 android.os.Debug.stopMethodTracing();
477 }
478
479 if (!mRestoring) {
480 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
481 // If the user leaves launcher, then we should just load items asynchronously when
482 // they return.
483 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
484 } else {
485 // We only load the page synchronously if the user rotates (or triggers a
486 // configuration change) while launcher is in the foreground
487 mModel.startLoader(true, mWorkspace.getRestorePage());
488 }
489 }
490
491 // For handling default keys
492 mDefaultKeySsb = new SpannableStringBuilder();
493 Selection.setSelection(mDefaultKeySsb, 0);
494
495 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
496 registerReceiver(mCloseSystemDialogsReceiver, filter);
497
498 updateGlobalIcons();
499
500 // On large interfaces, we want the screen to auto-rotate based on the current orientation
501 unlockScreenOrientation(true);
502
503 <<<<<<< MINE
504 if (shouldShowIntroScreen()) {
505 showIntroScreen();
506 } else {
507 ||||||| BASE
508 showFirstRunActivity();
509 showFirstRunCling();
510 }
511 =======
512 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
513 // on the device, then we always show the first run cling experience (or if there is no
514 // launcher2). Otherwise, we prompt the user upon started for migration
515 >>>>>>> YOURS
516 showFirstRunActivity();
517 <<<<<<< MINE
518 showFirstRunClings();
519 ||||||| BASE
520 =======
521 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
522 if (mModel.canMigrateFromOldLauncherDb(this)) {
523 mLauncherClings.showMigrationCling();
524 } else {
525 mLauncherClings.showFirstRunCling();
526 }
527 } else {
528 mLauncherClings.removeFirstRunAndMigrationClings();
529 >>>>>>> YOURS
530 }
531 }
532
533 @Override
534 public void onLauncherProviderChange() { }
535
536 /** To be overriden by subclasses to hint to Launcher that we have custom content */
537 protected boolean hasCustomContentToLeft() {
538 return false;
539 }
540
541 /**
542 * To be overridden by subclasses to populate the custom content container and call
543 * {@link #addToCustomContentPage}. This will only be invoked if
544 * {@link #hasCustomContentToLeft()} is {@code true}.
545 */
546 protected void populateCustomContentContainer() {
547 }
548
549 /**
550 * To be overridden by subclasses to indicate that there is an activity to launch
551 * before showing the standard launcher experience.
552 */
553 protected boolean hasFirstRunActivity() {
554 return false;
555 }
556
557 /**
558 * To be overridden by subclasses to launch any first run activity
559 */
560 protected Intent getFirstRunActivity() {
561 return null;
562 }
563
564 /**
565 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
566 * ensure the custom content page is added or removed if necessary.
567 */
568 protected void invalidateHasCustomContentToLeft() {
569 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
570 // Not bound yet, wait for bindScreens to be called.
571 return;
572 }
573
574 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
575 // Create the custom content page and call the subclass to populate it.
576 mWorkspace.createCustomContentContainer();
577 populateCustomContentContainer();
578 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
579 mWorkspace.removeCustomContentPage();
580 }
581 }
582
583 private void updateGlobalIcons() {
584 boolean searchVisible = false;
585 boolean voiceVisible = false;
586 // If we have a saved version of these external icons, we load them up immediately
587 int coi = getCurrentOrientationIndexForGlobalIcons();
588 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
589 searchVisible = updateGlobalSearchIcon();
590 voiceVisible = updateVoiceSearchIcon(searchVisible);
591 }
592 if (sGlobalSearchIcon[coi] != null) {
593 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
594 searchVisible = true;
595 }
596 if (sVoiceSearchIcon[coi] != null) {
597 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
598 voiceVisible = true;
599 }
600 if (mSearchDropTargetBar != null) {
601 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
602 }
603 }
604
605 private void checkForLocaleChange() {
606 if (sLocaleConfiguration == null) {
607 new AsyncTask<Void, Void, LocaleConfiguration>() {
608 @Override
609 protected LocaleConfiguration doInBackground(Void... unused) {
610 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
611 readConfiguration(Launcher.this, localeConfiguration);
612 return localeConfiguration;
613 }
614
615 @Override
616 protected void onPostExecute(LocaleConfiguration result) {
617 sLocaleConfiguration = result;
618 checkForLocaleChange(); // recursive, but now with a locale configuration
619 }
620 }.execute();
621 return;
622 }
623
624 final Configuration configuration = getResources().getConfiguration();
625
626 final String previousLocale = sLocaleConfiguration.locale;
627 final String locale = configuration.locale.toString();
628
629 final int previousMcc = sLocaleConfiguration.mcc;
630 final int mcc = configuration.mcc;
631
632 final int previousMnc = sLocaleConfiguration.mnc;
633 final int mnc = configuration.mnc;
634
635 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMn🔵
636
637 if (localeChanged) {
638 sLocaleConfiguration.locale = locale;
639 sLocaleConfiguration.mcc = mcc;
640 sLocaleConfiguration.mnc = mnc;
641
642 mIconCache.flush();
643
644 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
645 new AsyncTask<Void, Void, Void>() {
646 public Void doInBackground(Void ... args) {
647 writeConfiguration(Launcher.this, localeConfiguration);
648 return null;
649 }
650 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
651 }
652 }
653
654 private static class LocaleConfiguration {
655 public String locale;
656 public int mcc = -1;
657 public int mnc = -1;
658 }
659
660 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
661 DataInputStream in = null;
662 try {
663 in = new DataInputStream(context.openFileInput(PREFERENCES));
664 configuration.locale = in.readUTF();
665 configuration.mcc = in.readInt();
666 configuration.mnc = in.readInt();
667 } catch (FileNotFoundException e) {
668 // Ignore
669 } catch (IOException e) {
670 // Ignore
671 } finally {
672 if (in != null) {
673 try {
674 in.close();
675 } catch (IOException e) {
676 // Ignore
677 }
678 }
679 }
680 }
681
682 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
683 DataOutputStream out = null;
684 try {
685 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
686 out.writeUTF(configuration.locale);
687 out.writeInt(configuration.mcc);
688 out.writeInt(configuration.mnc);
689 out.flush();
690 } catch (FileNotFoundException e) {
691 // Ignore
692 } catch (IOException e) {
693 //noinspection ResultOfMethodCallIgnored
694 context.getFileStreamPath(PREFERENCES).delete();
695 } finally {
696 if (out != null) {
697 try {
698 out.close();
699 } catch (IOException e) {
700 // Ignore
701 }
702 }
703 }
704 }
705
706 public Stats getStats() {
707 return mStats;
708 }
709
710 public LayoutInflater getInflater() {
711 return mInflater;
712 }
713
714 boolean isDraggingEnabled() {
715 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
716 // that is subsequently removed from the workspace in startBinding().
717 return !mModel.isLoadingWorkspace();
718 }
719
720 static int getScreen() {
721 synchronized (sLock) {
722 return sScreen;
723 }
724 }
725
726 static void setScreen(int screen) {
727 synchronized (sLock) {
728 sScreen = screen;
729 }
730 }
731
732 public static int generateViewId() {
733 if (Build.VERSION.SDK_INT >= 17) {
734 return View.generateViewId();
735 } else {
736 // View.generateViewId() is not available. The following fallback logic is a copy
737 // of its implementation.
738 for (;;) {
739 final int result = sNextGeneratedId.get();
740 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
741 int newValue = result + 1;
742 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
743 if (sNextGeneratedId.compareAndSet(result, newValue)) {
744 return result;
745 }
746 }
747 }
748 }
749
750 public int getViewIdForItem(ItemInfo info) {
751 // This cast is safe given the > 2B range for int.
752 int itemId = (int) info.id;
753 if (mItemIdToViewId.containsKey(itemId)) {
754 return mItemIdToViewId.get(itemId);
755 }
756 int viewId = generateViewId();
757 mItemIdToViewId.put(itemId, viewId);
758 return viewId;
759 }
760
761 /**
762 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
763 * a configuration step, this allows the proper animations to run after other transitions.
764 */
765 private long completeAdd(PendingAddArguments args) {
766 long screenId = args.screenId;
767 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
768 // When the screen id represents an actual screen (as opposed to a rank) we make sure
769 // that the drop page actually exists.
770 screenId = ensurePendingDropLayoutExists(args.screenId);
771 }
772
773 switch (args.requestCode) {
774 case REQUEST_CREATE_SHORTCUT:
775 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
776 args.cellY);
777 break;
778 case REQUEST_CREATE_APPWIDGET:
779 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
780 break;
781 case REQUEST_RECONFIGURE_APPWIDGET:
782 completeRestoreAppWidget(args.appWidgetId);
783 break;
784 }
785 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
786 // if you turned the screen off and then back while in All Apps, Launcher would not
787 // return to the workspace. Clearing mAddInfo.container here fixes this issue
788 resetAddInfo();
789 return screenId;
790 }
791
792 @Override
793 protected void onActivityResult(
794 final int requestCode, final int resultCode, final Intent data) {
795 // Reset the startActivity waiting flag
796 setWaitingForResult(false);
797 final int pendingAddWidgetId = mPendingAddWidgetId;
798 mPendingAddWidgetId = -1;
799
800 Runnable exitSpringLoaded = new Runnable() {
801 @Override
802 public void run() {
803 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
804 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
805 }
806 };
807
808 if (requestCode == REQUEST_BIND_APPWIDGET) {
809 final int appWidgetId = data != null ?
810 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
811 if (resultCode == RESULT_CANCELED) {
812 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
813 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
814 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
815 } else if (resultCode == RESULT_OK) {
816 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
817 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
818 }
819 return;
820 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
821 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
822 mWorkspace.exitOverviewMode(false);
823 }
824 return;
825 }
826
827 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
828 requestCode == REQUEST_CREATE_APPWIDGET);
829
830 final boolean workspaceLocked = isWorkspaceLocked();
831 // We have special handling for widgets
832 if (isWidgetDrop) {
833 final int appWidgetId;
834 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
835 : -1;
836 if (widgetId < 0) {
837 appWidgetId = pendingAddWidgetId;
838 } else {
839 appWidgetId = widgetId;
840 }
841
842 final int result;
843 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
844 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
845 "returned from the widget configuration activity.");
846 result = RESULT_CANCELED;
847 completeTwoStageWidgetDrop(result, appWidgetId);
848 final Runnable onComplete = new Runnable() {
849 @Override
850 public void run() {
851 exitSpringLoadedDragModeDelayed(false, 0, null);
852 }
853 };
854 if (workspaceLocked) {
855 // No need to remove the empty screen if we're mid-binding, as the
856 // the bind will not add the empty screen.
857 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
858 } else {
859 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
860 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
861 }
862 } else {
863 if (!workspaceLocked) {
864 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
865 // When the screen id represents an actual screen (as opposed to a rank)
866 // we make sure that the drop page actually exists.
867 mPendingAddInfo.screenId =
868 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
869 }
870 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
871
872 dropLayout.setDropPending(true);
873 final Runnable onComplete = new Runnable() {
874 @Override
875 public void run() {
876 completeTwoStageWidgetDrop(resultCode, appWidgetId);
877 dropLayout.setDropPending(false);
878 }
879 };
880 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
881 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
882 } else {
883 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
884 mPendingAddInfo);
885 sPendingAddItem = args;
886 }
887 }
888 return;
889 }
890
891 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
892 if (resultCode == RESULT_OK) {
893 // Update the widget view.
894 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
895 pendingAddWidgetId, mPendingAddInfo);
896 if (workspaceLocked) {
897 sPendingAddItem = args;
898 } else {
899 completeAdd(args);
900 }
901 }
902 // Leave the widget in the pending state if the user canceled the configure.
903 return;
904 }
905
906 // The pattern used here is that a user PICKs a specific application,
907 // which, depending on the target, might need to CREATE the actual target.
908
909 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
910 // launch over to the Music app to actually CREATE_SHORTCUT.
911 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
912 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
913 mPendingAddInfo);
914 if (isWorkspaceLocked()) {
915 sPendingAddItem = args;
916 } else {
917 completeAdd(args);
918 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
919 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
920 }
921 } else if (resultCode == RESULT_CANCELED) {
922 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
923 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
924 }
925 mDragLayer.clearAnimatedView();
926 }
927
928 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
929 appWidgetId, ItemInfo info) {
930 PendingAddArguments args = new PendingAddArguments();
931 args.requestCode = requestCode;
932 args.intent = data;
933 args.container = info.container;
934 args.screenId = info.screenId;
935 args.cellX = info.cellX;
936 args.cellY = info.cellY;
937 args.appWidgetId = appWidgetId;
938 return args;
939 }
940
941 /**
942 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
943 *
944 * @param screenId the screen id to check
945 * @return the new screen, or screenId if it exists
946 */
947 private long ensurePendingDropLayoutExists(long screenId) {
948 CellLayout dropLayout =
949 (CellLayout) mWorkspace.getScreenWithId(screenId);
950 if (dropLayout == null) {
951 // it's possible that the add screen was removed because it was
952 // empty and a re-bind occurred
953 mWorkspace.addExtraEmptyScreen();
954 return mWorkspace.commitExtraEmptyScreen();
955 } else {
956 return screenId;
957 }
958 }
959
960 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
961 CellLayout cellLayout =
962 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
963 Runnable onCompleteRunnable = null;
964 int animationType = 0;
965
966 AppWidgetHostView boundWidget = null;
967 if (resultCode == RESULT_OK) {
968 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
969 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
970 mPendingAddWidgetInfo);
971 boundWidget = layout;
972 onCompleteRunnable = new Runnable() {
973 @Override
974 public void run() {
975 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
976 mPendingAddInfo.screenId, layout, null);
977 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
978 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
979 }
980 };
981 } else if (resultCode == RESULT_CANCELED) {
982 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
983 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
984 }
985 if (mDragLayer.getAnimatedView() != null) {
986 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
987 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
988 animationType, boundWidget, true);
989 } else if (onCompleteRunnable != null) {
990 // The animated view may be null in the case of a rotation during widget configuration
991 onCompleteRunnable.run();
992 }
993 }
994
995 @Override
996 protected void onStop() {
997 super.onStop();
998 FirstFrameAnimatorHelper.setIsVisible(false);
999 }
1000
1001 @Override
1002 protected void onStart() {
1003 super.onStart();
1004 FirstFrameAnimatorHelper.setIsVisible(true);
1005 }
1006
1007 @Override
1008 protected void onResume() {
1009 long startTime = 0;
1010 if (DEBUG_RESUME_TIME) {
1011 startTime = System.currentTimeMillis();
1012 Log.v(TAG, "Launcher.onResume()");
1013 }
1014 super.onResume();
1015
1016 // Restore the previous launcher state
1017 if (mOnResumeState == State.WORKSPACE) {
1018 showWorkspace(false);
1019 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
1020 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
1021 }
1022 mOnResumeState = State.NONE;
1023
1024 // Background was set to gradient in onPause(), restore to black if in all apps.
1025 setWorkspaceBackground(mState == State.WORKSPACE);
1026
1027 mPaused = false;
1028 if (mRestoring || mOnResumeNeedsLoad) {
1029 setWorkspaceLoading(true);
1030 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
1031 mRestoring = false;
1032 mOnResumeNeedsLoad = false;
1033 }
1034 if (mBindOnResumeCallbacks.size() > 0) {
1035 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1036 // execute them here
1037 long startTimeCallbacks = 0;
1038 if (DEBUG_RESUME_TIME) {
1039 startTimeCallbacks = System.currentTimeMillis();
1040 }
1041
1042 if (mAppsCustomizeContent != null) {
1043 mAppsCustomizeContent.setBulkBind(true);
1044 }
1045 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1046 mBindOnResumeCallbacks.get(i).run();
1047 }
1048 if (mAppsCustomizeContent != null) {
1049 mAppsCustomizeContent.setBulkBind(false);
1050 }
1051 mBindOnResumeCallbacks.clear();
1052 if (DEBUG_RESUME_TIME) {
1053 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1054 (System.currentTimeMillis() - startTimeCallbacks));
1055 }
1056 }
1057 if (mOnResumeCallbacks.size() > 0) {
1058 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1059 mOnResumeCallbacks.get(i).run();
1060 }
1061 mOnResumeCallbacks.clear();
1062 }
1063
1064 // Reset the pressed state of icons that were locked in the press state while activities
1065 // were launching
1066 if (mWaitingForResume != null) {
1067 // Resets the previous workspace icon press state
1068 mWaitingForResume.setStayPressed(false);
1069 }
1070
1071 // It is possible that widgets can receive updates while launcher is not in the foreground.
1072 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1073 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1074 // orientation.
1075 getWorkspace().reinflateWidgetsIfNecessary();
1076
1077 // Process any items that were added while Launcher was away.
1078 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1079
1080 // Update the voice search button proxy
1081 updateVoiceButtonProxyVisible(false);
1082
1083 // Again, as with the above scenario, it's possible that one or more of the global icons
1084 // were updated in the wrong orientation.
1085 updateGlobalIcons();
1086 if (DEBUG_RESUME_TIME) {
1087 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1088 }
1089
1090 if (mWorkspace.getCustomContentCallbacks() != null) {
1091 // If we are resuming and the custom content is the current page, we call onShow().
1092 // It is also poassible that onShow will instead be called slightly after first layout
1093 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1094 if (mWorkspace.isOnOrMovingToCustomContent()) {
1095 mWorkspace.getCustomContentCallbacks().onShow(true);
1096 }
1097 }
1098 mWorkspace.updateInteractionForState();
1099 mWorkspace.onResume();
1100
1101 PackageInstallerCompat.getInstance(this).onResume();
1102 }
1103
1104 @Override
1105 protected void onPause() {
1106 // Ensure that items added to Launcher are queued until Launcher returns
1107 InstallShortcutReceiver.enableInstallQueue();
1108 PackageInstallerCompat.getInstance(this).onPause();
1109
1110 super.onPause();
1111 mPaused = true;
1112 mDragController.cancelDrag();
1113 mDragController.resetLastGestureUpTime();
1114
1115 // We call onHide() aggressively. The custom content callbacks should be able to
1116 // debounce excess onHide calls.
1117 if (mWorkspace.getCustomContentCallbacks() != null) {
1118 mWorkspace.getCustomContentCallbacks().onHide();
1119 }
1120 }
1121
1122 QSBScroller mQsbScroller = new QSBScroller() {
1123 int scrollY = 0;
1124
1125 @Override
1126 public void setScrollY(int scroll) {
1127 scrollY = scroll;
1128
1129 if (mWorkspace.isOnOrMovingToCustomContent()) {
1130 mSearchDropTargetBar.setTranslationY(- scrollY);
1131 getQsbBar().setTranslationY(-scrollY);
1132 }
1133 }
1134 };
1135
1136 public void resetQSBScroll() {
1137 mSearchDropTargetBar.animate().translationY(0).start();
1138 getQsbBar().animate().translationY(0).start();
1139 }
1140
1141 public interface CustomContentCallbacks {
1142 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1143 // by a onResume or by scrolling otherwise.
1144 public void onShow(boolean fromResume);
1145
1146 // Custom content is completely hidden
1147 public void onHide();
1148
1149 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1150 public void onScrollProgressChanged(float progress);
1151
1152 // Indicates whether the user is allowed to scroll away from the custom content.
1153 boolean isScrollingAllowed();
1154 }
1155
1156 protected boolean hasSettings() {
1157 return false;
1158 }
1159
1160 public interface QSBScroller {
1161 public void setScrollY(int scrollY);
1162 }
1163
1164 public QSBScroller addToCustomContentPage(View customContent,
1165 CustomContentCallbacks callbacks, String description) {
1166 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
1167 return mQsbScroller;
1168 }
1169
1170 // The custom content needs to offset its content to account for the QSB
1171 public int getTopOffsetForCustomContent() {
1172 return mWorkspace.getPaddingTop();
1173 }
1174
1175 @Override
1176 public Object onRetainNonConfigurationInstance() {
1177 // Flag the loader to stop early before switching
1178 if (mModel.isCurrentCallbacks(this)) {
1179 mModel.stopLoader();
1180 }
1181 if (mAppsCustomizeContent != null) {
1182 mAppsCustomizeContent.surrender();
1183 }
1184 return Boolean.TRUE;
1185 }
1186
1187 // We can't hide the IME if it was forced open. So don't bother
1188 @Override
1189 public void onWindowFocusChanged(boolean hasFocus) {
1190 super.onWindowFocusChanged(hasFocus);
1191 mHasFocus = hasFocus;
1192 }
1193
1194 private boolean acceptFilter() {
1195 final InputMethodManager inputManager = (InputMethodManager)
1196 getSystemService(Context.INPUT_METHOD_SERVICE);
1197 return !inputManager.isFullscreenMode();
1198 }
1199
1200 @Override
1201 public boolean onKeyDown(int keyCode, KeyEvent event) {
1202 final int uniChar = event.getUnicodeChar();
1203 final boolean handled = super.onKeyDown(keyCode, event);
1204 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1205 if (!handled && acceptFilter() && isKeyNotWhitespace) {
1206 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1207 keyCode, event);
1208 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
1209 // something usable has been typed - start a search
1210 // the typed text will be retrieved and cleared by
1211 // showSearchDialog()
1212 // If there are multiple keystrokes before the search dialog takes focus,
1213 // onSearchRequested() will be called for every keystroke,
1214 // but it is idempotent, so it's fine.
1215 return onSearchRequested();
1216 }
1217 }
1218
1219 // Eat the long press event so the keyboard doesn't come up.
1220 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1221 return true;
1222 }
1223
1224 return handled;
1225 }
1226
1227 private String getTypedText() {
1228 return mDefaultKeySsb.toString();
1229 }
1230
1231 private void clearTypedText() {
1232 mDefaultKeySsb.clear();
1233 mDefaultKeySsb.clearSpans();
1234 Selection.setSelection(mDefaultKeySsb, 0);
1235 }
1236
1237 /**
1238 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1239 * State
1240 */
1241 private static State intToState(int stateOrdinal) {
1242 State state = State.WORKSPACE;
1243 final State[] stateValues = State.values();
1244 for (int i = 0; i < stateValues.length; i++) {
1245 if (stateValues[i].ordinal() == stateOrdinal) {
1246 state = stateValues[i];
1247 break;
1248 }
1249 }
1250 return state;
1251 }
1252
1253 /**
1254 * Restores the previous state, if it exists.
1255 *
1256 * @param savedState The previous state.
1257 */
1258 @SuppressWarnings("unchecked")
1259 private void restoreState(Bundle savedState) {
1260 if (savedState == null) {
1261 return;
1262 }
1263
1264 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
1265 if (state == State.APPS_CUSTOMIZE) {
1266 mOnResumeState = State.APPS_CUSTOMIZE;
1267 }
1268
1269 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1270 PagedView.INVALID_RESTORE_PAGE);
1271 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
1272 mWorkspace.setRestorePage(currentScreen);
1273 }
1274
1275 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
1276 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
1277
1278 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1279 mPendingAddInfo.container = pendingAddContainer;
1280 mPendingAddInfo.screenId = pendingAddScreen;
1281 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1282 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
1283 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1284 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1285 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
1286 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
1287 setWaitingForResult(true);
1288 mRestoring = true;
1289 }
1290
1291 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1292 if (renameFolder) {
1293 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
1294 mFolderInfo = mModel.getFolderById(this, sFolders, id);
1295 mRestoring = true;
1296 }
1297
1298 // Restore the AppsCustomize tab
1299 if (mAppsCustomizeTabHost != null) {
1300 String curTab = savedState.getString("apps_customize_currentTab");
1301 if (curTab != null) {
1302 mAppsCustomizeTabHost.setContentTypeImmediate(
1303 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
1304 mAppsCustomizeContent.loadAssociatedPages(
1305 mAppsCustomizeContent.getCurrentPage());
1306 }
1307
1308 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1309 mAppsCustomizeContent.restorePageForIndex(currentIndex);
1310 }
1311 mItemIdToViewId = (HashMap<Integer, Integer>)
1312 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
1313 }
1314
1315 /**
1316 * Finds all the views we need and configure them properly.
1317 */
1318 private void setupViews() {
1319 final DragController dragController = mDragController;
1320
1321 mLauncherView = findViewById(R.id.launcher);
1322 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
1323 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1324 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
1325 <<<<<<< MINE
1326 mWorkspace.setPageSwitchListener(this);
1327 ||||||| BASE
1328
1329 mLauncherView.setSystemUiVisibility(
1330 =======
1331 >>>>>>> YOURS
1332 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
1333
1334 mLauncherView.setSystemUiVisibility(
1335 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1336 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
1337
1338 // Setup the drag layer
1339 mDragLayer.setup(this, dragController);
1340
1341 // Setup the hotseat
1342 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1343 if (mHotseat != null) {
1344 mHotseat.setup(this);
1345 mHotseat.setOnLongClickListener(this);
1346 }
1347
1348 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1349 View widgetButton = findViewById(R.id.widget_button);
1350 widgetButton.setOnClickListener(new OnClickListener() {
1351 @Override
1352 public void onClick(View arg0) {
1353 if (!mWorkspace.isSwitchingState()) {
1354 onClickAddWidgetButton(arg0);
1355 }
1356 }
1357 });
1358 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1359
1360 View wallpaperButton = findViewById(R.id.wallpaper_button);
1361 wallpaperButton.setOnClickListener(new OnClickListener() {
1362 @Override
1363 public void onClick(View arg0) {
1364 if (!mWorkspace.isSwitchingState()) {
1365 onClickWallpaperPicker(arg0);
1366 }
1367 }
1368 });
1369 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1370
1371 View settingsButton = findViewById(R.id.settings_button);
1372 if (hasSettings()) {
1373 settingsButton.setOnClickListener(new OnClickListener() {
1374 @Override
1375 public void onClick(View arg0) {
1376 if (!mWorkspace.isSwitchingState()) {
1377 onClickSettingsButton(arg0);
1378 }
1379 }
1380 });
1381 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1382 } else {
1383 settingsButton.setVisibility(View.GONE);
1384 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1385 lp.gravity = Gravity.END | Gravity.TOP;
1386 widgetButton.requestLayout();
1387 }
1388
1389 mOverviewPanel.setAlpha(0f);
1390
1391 // Setup the workspace
1392 mWorkspace.setHapticFeedbackEnabled(false);
1393 mWorkspace.setOnLongClickListener(this);
1394 mWorkspace.setup(dragController);
1395 dragController.addDragListener(mWorkspace);
1396
1397 // Get the search/delete bar
1398 mSearchDropTargetBar = (SearchDropTargetBar)
1399 mDragLayer.findViewById(R.id.search_drop_target_bar);
1400
1401 // Setup AppsCustomize
1402 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
1403 mAppsCustomizeContent = (AppsCustomizePagedView)
1404 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1405 mAppsCustomizeContent.setup(this, dragController);
1406
1407 // Setup the drag controller (drop targets have to be added in reverse order in priority)
1408 dragController.setDragScoller(mWorkspace);
1409 dragController.setScrollView(mDragLayer);
1410 dragController.setMoveTarget(mWorkspace);
1411 dragController.addDropTarget(mWorkspace);
1412 if (mSearchDropTargetBar != null) {
1413 mSearchDropTargetBar.setup(this, dragController);
1414 }
1415
1416 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
1417 Log.v(TAG, "adding WeightWatcher");
1418 mWeightWatcher = new WeightWatcher(this);
1419 mWeightWatcher.setAlpha(0.5f);
1420 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
1421 new FrameLayout.LayoutParams(
1422 FrameLayout.LayoutParams.MATCH_PARENT,
1423 FrameLayout.LayoutParams.WRAP_CONTENT,
1424 Gravity.BOTTOM)
1425 );
1426
1427 boolean show = shouldShowWeightWatcher();
1428 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
1429 }
1430 }
1431
1432 /**
1433 * Sets the all apps button. This method is called from {@link Hotseat}.
1434 */
1435 public void setAllAppsButton(View allAppsButton) {
1436 mAllAppsButton = allAppsButton;
1437 }
1438
1439 public View getAllAppsButton() {
1440 return mAllAppsButton;
1441 }
1442
1443 /**
1444 * Creates a view representing a shortcut.
1445 *
1446 * @param info The data structure describing the shortcut.
1447 *
1448 * @return A View inflated from R.layout.application.
1449 */
1450 View createShortcut(ShortcutInfo info) {
1451 return createShortcut(R.layout.application,
1452 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
1453 }
1454
1455 /**
1456 * Creates a view representing a shortcut inflated from the specified resource.
1457 *
1458 * @param layoutResId The id of the XML layout used to create the shortcut.
1459 * @param parent The group the shortcut belongs to.
1460 * @param info The data structure describing the shortcut.
1461 *
1462 * @return A View inflated from layoutResId.
1463 */
1464 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
1465 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1466 favorite.applyFromShortcutInfo(info, mIconCache, true);
1467 favorite.setOnClickListener(this);
1468 favorite.setOnFocusChangeListener(mFocusHandler);
1469 return favorite;
1470 }
1471
1472 /**
1473 * Add a shortcut to the workspace.
1474 *
1475 * @param data The intent describing the shortcut.
1476 * @param cellInfo The position on screen where to create the shortcut.
1477 */
1478 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
1479 int cellY) {
1480 int[] cellXY = mTmpAddItemCellCoordinates;
1481 int[] touchXY = mPendingAddInfo.dropPos;
1482 CellLayout layout = getCellLayout(container, screenId);
1483
1484 boolean foundCellSpan = false;
1485
1486 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
1487 if (info == null) {
1488 return;
1489 }
1490 final View view = createShortcut(info);
1491
1492 // First we check if we already know the exact location where we want to add this item.
1493 if (cellX >= 0 && cellY >= 0) {
1494 cellXY[0] = cellX;
1495 cellXY[1] = cellY;
1496 foundCellSpan = true;
1497
1498 // If appropriate, either create a folder or add to an existing folder
1499 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
1500 true, null,null)) {
1501 return;
1502 }
1503 DragObject dragObject = new DragObject();
1504 dragObject.dragInfo = info;
1505 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1506 true)) {
1507 return;
1508 }
1509 } else if (touchXY != null) {
1510 // when dragging and dropping, just find the closest free spot
1511 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
1512 foundCellSpan = (result != null);
1513 } else {
1514 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1515 }
1516
1517 if (!foundCellSpan) {
1518 showOutOfSpaceMessage(isHotseatLayout(layout));
1519 return;
1520 }
1521
1522 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
1523
1524 if (!mRestoring) {
1525 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
1526 isWorkspaceLocked());
1527 }
1528 }
1529
1530 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1531 int minHeight) {
1532 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
1533 // We want to account for the extra amount of padding that we are adding to the widget
1534 // to ensure that it gets the full amount of space that it has requested
1535 int requiredWidth = minWidth + padding.left + padding.right;
1536 int requiredHeight = minHeight + padding.top + padding.bottom;
1537 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
1538 }
1539
1540 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1541 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
1542 }
1543
1544 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1545 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
1546 }
1547
1548 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1549 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
1550 }
1551
1552 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1553 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
1554 info.minResizeHeight);
1555 }
1556
1557 /**
1558 * Add a widget to the workspace.
1559 *
1560 * @param appWidgetId The app widget id
1561 * @param cellInfo The position on screen where to create the widget.
1562 */
1563 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
1564 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1565 if (appWidgetInfo == null) {
1566 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1567 }
1568
1569 // Calculate the grid spans needed to fit this widget
1570 CellLayout layout = getCellLayout(container, screenId);
1571
1572 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1573 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
1574
1575 // Try finding open space on Launcher screen
1576 // We have saved the position to which the widget was dragged-- this really only matters
1577 // if we are placing widgets on a "spring-loaded" screen
1578 int[] cellXY = mTmpAddItemCellCoordinates;
1579 int[] touchXY = mPendingAddInfo.dropPos;
1580 int[] finalSpan = new int[2];
1581 boolean foundCellSpan = false;
1582 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1583 cellXY[0] = mPendingAddInfo.cellX;
1584 cellXY[1] = mPendingAddInfo.cellY;
1585 spanXY[0] = mPendingAddInfo.spanX;
1586 spanXY[1] = mPendingAddInfo.spanY;
1587 foundCellSpan = true;
1588 } else if (touchXY != null) {
1589 // when dragging and dropping, just find the closest free spot
1590 int[] result = layout.findNearestVacantArea(
1591 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1592 spanXY[1], cellXY, finalSpan);
1593 spanXY[0] = finalSpan[0];
1594 spanXY[1] = finalSpan[1];
1595 foundCellSpan = (result != null);
1596 } else {
1597 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
1598 }
1599
1600 if (!foundCellSpan) {
1601 if (appWidgetId != -1) {
1602 // Deleting an app widget ID is a void call but writes to disk before returning
1603 // to the caller...
1604 new AsyncTask<Void, Void, Void>() {
1605 public Void doInBackground(Void ... args) {
1606 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1607 return null;
1608 }
1609 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
1610 }
1611 showOutOfSpaceMessage(isHotseatLayout(layout));
1612 return;
1613 }
1614
1615 // Build Launcher-specific widget info and save to database
1616 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1617 appWidgetInfo.provider);
1618 launcherInfo.spanX = spanXY[0];
1619 launcherInfo.spanY = spanXY[1];
1620 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1621 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
1622 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
1623
1624 LauncherModel.addItemToDatabase(this, launcherInfo,
1625 container, screenId, cellXY[0], cellXY[1], false);
1626
1627 if (!mRestoring) {
1628 if (hostView == null) {
1629 // Perform actual inflation because we're live
1630 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1631 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1632 } else {
1633 // The AppWidgetHostView has already been inflated and instantiated
1634 launcherInfo.hostView = hostView;
1635 }
1636
1637 launcherInfo.hostView.setTag(launcherInfo);
1638 launcherInfo.hostView.setVisibility(View.VISIBLE);
1639 launcherInfo.notifyWidgetSizeChanged(this);
1640
1641 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
1642 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
1643
1644 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
1645 }
1646 resetAddInfo();
1647 }
1648
1649 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1650 @Override
1651 public void onReceive(Context context, Intent intent) {
1652 final String action = intent.getAction();
1653 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1654 mUserPresent = false;
1655 mDragLayer.clearAllResizeFrames();
1656 updateRunning();
1657
1658 // Reset AllApps to its initial state only if we are not in the middle of
1659 // processing a multi-step drop
1660 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1661 showWorkspace(false);
1662 }
1663 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1664 mUserPresent = true;
1665 updateRunning();
1666 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1667 mModel.resetLoadedState(false, true);
1668 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1669 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1670 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1671 mModel.resetLoadedState(false, true);
1672 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1673 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1674 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
1675 <<<<<<< MINE
1676 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1677 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1678 getModel().forceReload();
1679 ||||||| BASE
1680 =======
1681 >>>>>>> YOURS
1682 }
1683 }
1684 };
1685
1686 @Override
1687 public void onAttachedToWindow() {
1688 super.onAttachedToWindow();
1689
1690 // Listen for broadcasts related to user-presence
1691 final IntentFilter filter = new IntentFilter();
1692 filter.addAction(Intent.ACTION_SCREEN_OFF);
1693 filter.addAction(Intent.ACTION_USER_PRESENT);
1694 <<<<<<< MINE
1695 // For handling managed profiles
1696 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1697 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
1698 ||||||| BASE
1699 registerReceiver(mReceiver, filter);
1700 =======
1701 >>>>>>> YOURS
1702 if (ENABLE_DEBUG_INTENTS) {
1703 filter.addAction(DebugIntents.DELETE_DATABASE);
1704 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1705 }
1706 registerReceiver(mReceiver, filter);
1707 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
1708 setupTransparentSystemBarsForLmp();
1709 mAttached = true;
1710 mVisible = true;
1711 }
1712
1713 /**
1714 * Sets up transparent navigation and status bars in LMP.
1715 * This method is a no-op for other platform versions.
1716 */
1717 @TargetApi(19)
1718 private void setupTransparentSystemBarsForLmp() {
1719 // TODO(sansid): use the APIs directly when compiling against L sdk.
1720 // Currently we use reflection to access the flags and the API to set the transparency
1721 // on the System bars.
1722 if (Utilities.isLmpOrAbove()) {
1723 try {
1724 getWindow().getAttributes().systemUiVisibility |=
1725 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1726 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1727 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1728 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1729 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1730 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1731 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1732 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1733
1734 Method setStatusBarColorMethod =
1735 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1736 Method setNavigationBarColorMethod =
1737 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1738 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1739 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1740 } catch (NoSuchFieldException e) {
1741 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1742 } catch (NoSuchMethodException ex) {
1743 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1744 } catch (IllegalAccessException e) {
1745 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1746 } catch (IllegalArgumentException e) {
1747 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1748 } catch (InvocationTargetException e) {
1749 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1750 } finally {}
1751 }
1752 }
1753
1754 @Override
1755 public void onDetachedFromWindow() {
1756 super.onDetachedFromWindow();
1757 mVisible = false;
1758
1759 if (mAttached) {
1760 unregisterReceiver(mReceiver);
1761 mAttached = false;
1762 }
1763 updateRunning();
1764 }
1765
1766 public void onWindowVisibilityChanged(int visibility) {
1767 mVisible = visibility == View.VISIBLE;
1768 updateRunning();
1769 // The following code used to be in onResume, but it turns out onResume is called when
1770 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1771 // is a more appropriate event to handle
1772 if (mVisible) {
1773 mAppsCustomizeTabHost.onWindowVisible();
1774 if (!mWorkspaceLoading) {
1775 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
1776 // We want to let Launcher draw itself at least once before we force it to build
1777 // layers on all the workspace pages, so that transitioning to Launcher from other
1778 // apps is nice and speedy.
1779 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
1780 private boolean mStarted = false;
1781 public void onDraw() {
1782 if (mStarted) return;
1783 mStarted = true;
1784 // We delay the layer building a bit in order to give
1785 // other message processing a time to run. In particular
1786 // this avoids a delay in hiding the IME if it was
1787 // currently shown, because doing that may involve
1788 // some communication back with the app.
1789 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
1790 final ViewTreeObserver.OnDrawListener listener = this;
1791 mWorkspace.post(new Runnable() {
1792 public void run() {
1793 if (mWorkspace != null &&
1794 mWorkspace.getViewTreeObserver() != null) {
1795 mWorkspace.getViewTreeObserver().
1796 removeOnDrawListener(listener);
1797 }
1798 }
1799 });
1800 return;
1801 }
1802 });
1803 }
1804 clearTypedText();
1805 }
1806 }
1807
1808 private void sendAdvanceMessage(long delay) {
1809 mHandler.removeMessages(ADVANCE_MSG);
1810 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1811 mHandler.sendMessageDelayed(msg, delay);
1812 mAutoAdvanceSentTime = System.currentTimeMillis();
1813 }
1814
1815 private void updateRunning() {
1816 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1817 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1818 mAutoAdvanceRunning = autoAdvanceRunning;
1819 if (autoAdvanceRunning) {
1820 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1821 sendAdvanceMessage(delay);
1822 } else {
1823 if (!mWidgetsToAdvance.isEmpty()) {
1824 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1825 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1826 }
1827 mHandler.removeMessages(ADVANCE_MSG);
1828 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
1829 }
1830 }
1831 }
1832
1833 private final Handler mHandler = new Handler() {
1834 @Override
1835 public void handleMessage(Message msg) {
1836 if (msg.what == ADVANCE_MSG) {
1837 int i = 0;
1838 for (View key: mWidgetsToAdvance.keySet()) {
1839 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1840 final int delay = mAdvanceStagger * i;
1841 if (v instanceof Advanceable) {
1842 postDelayed(new Runnable() {
1843 public void run() {
1844 ((Advanceable) v).advance();
1845 }
1846 }, delay);
1847 }
1848 i++;
1849 }
1850 sendAdvanceMessage(mAdvanceInterval);
1851 }
1852 }
1853 };
1854
1855 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1856 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
1857 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1858 if (v instanceof Advanceable) {
1859 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1860 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
1861 updateRunning();
1862 }
1863 }
1864
1865 void removeWidgetToAutoAdvance(View hostView) {
1866 if (mWidgetsToAdvance.containsKey(hostView)) {
1867 mWidgetsToAdvance.remove(hostView);
1868 updateRunning();
1869 }
1870 }
1871
1872 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1873 removeWidgetToAutoAdvance(launcherInfo.hostView);
1874 launcherInfo.hostView = null;
1875 }
1876
1877 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1878 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1879 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
1880 }
1881
1882 public DragLayer getDragLayer() {
1883 return mDragLayer;
1884 }
1885
1886 public Workspace getWorkspace() {
1887 return mWorkspace;
1888 }
1889
1890 public Hotseat getHotseat() {
1891 return mHotseat;
1892 }
1893
1894 <<<<<<< MINE
1895 public ViewGroup getOverviewPanel() {
1896 ||||||| BASE
1897 View getOverviewPanel() {
1898 =======
1899 public View getOverviewPanel() {
1900 >>>>>>> YOURS
1901 return mOverviewPanel;
1902 }
1903
1904 public SearchDropTargetBar getSearchBar() {
1905 return mSearchDropTargetBar;
1906 }
1907
1908 public LauncherAppWidgetHost getAppWidgetHost() {
1909 return mAppWidgetHost;
1910 }
1911
1912 public LauncherModel getModel() {
1913 return mModel;
1914 }
1915
1916 public LauncherClings getLauncherClings() {
1917 return mLauncherClings;
1918 }
1919
1920 protected SharedPreferences getSharedPrefs() {
1921 return mSharedPrefs;
1922 }
1923
1924 public void closeSystemDialogs() {
1925 getWindow().closeAllPanels();
1926
1927 // Whatever we were doing is hereby canceled.
1928 setWaitingForResult(false);
1929 }
1930
1931 @Override
1932 protected void onNewIntent(Intent intent) {
1933 long startTime = 0;
1934 if (DEBUG_RESUME_TIME) {
1935 startTime = System.currentTimeMillis();
1936 }
1937 super.onNewIntent(intent);
1938
1939 // Close the menu
1940 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
1941 // also will cancel mWaitingForResult.
1942 closeSystemDialogs();
1943
1944 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1945 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1946 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1947
1948 if (mWorkspace == null) {
1949 // Can be cases where mWorkspace is null, this prevents a NPE
1950 return;
1951 }
1952 Folder openFolder = mWorkspace.getOpenFolder();
1953 // In all these cases, only animate if we're already on home
1954 mWorkspace.exitWidgetResizeMode();
1955 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1956 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
1957 mWorkspace.moveToDefaultScreen(true);
1958 }
1959
1960 closeFolder();
1961 exitSpringLoadedDragMode();
1962
1963 // If we are already on home, then just animate back to the workspace,
1964 // otherwise, just wait until onResume to set the state back to Workspace
1965 if (alreadyOnHome) {
1966 showWorkspace(true);
1967 } else {
1968 mOnResumeState = State.WORKSPACE;
1969 }
1970
1971 final View v = getWindow().peekDecorView();
1972 if (v != null && v.getWindowToken() != null) {
1973 InputMethodManager imm = (InputMethodManager)getSystemService(
1974 INPUT_METHOD_SERVICE);
1975 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
1976 }
1977
1978 // Reset the apps customize page
1979 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
1980 mAppsCustomizeTabHost.reset();
1981 }
1982
1983 onHomeIntent();
1984 }
1985
1986 if (DEBUG_RESUME_TIME) {
1987 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
1988 }
1989 }
1990
1991 /**
1992 * Override point for subclasses to prevent movement to the default screen when the home
1993 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
1994 */
1995 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
1996 return true;
1997 }
1998
1999 /**
2000 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
2001 */
2002 protected void onHomeIntent() {
2003 // Do nothing
2004 }
2005
2006 @Override
2007 public void onRestoreInstanceState(Bundle state) {
2008 super.onRestoreInstanceState(state);
2009 for (int page: mSynchronouslyBoundPages) {
2010 mWorkspace.restoreInstanceStateForChild(page);
2011 }
2012 }
2013
2014 @Override
2015 protected void onSaveInstanceState(Bundle outState) {
2016 if (mWorkspace.getChildCount() > 0) {
2017 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
2018 mWorkspace.getCurrentPageOffsetFromCustomContent());
2019 }
2020 super.onSaveInstanceState(outState);
2021
2022 outState.putInt(RUNTIME_STATE, mState.ordinal());
2023 // We close any open folder since it will not be re-opened, and we need to make sure
2024 // this state is reflected.
2025 closeFolder();
2026
2027 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
2028 mWaitingForResult) {
2029 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
2030 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
2031 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2032 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
2033 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2034 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2035 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
2036 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
2037 }
2038
2039 if (mFolderInfo != null && mWaitingForResult) {
2040 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2041 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2042 }
2043
2044 // Save the current AppsCustomize tab
2045 if (mAppsCustomizeTabHost != null) {
2046 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2047 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
2048 if (currentTabTag != null) {
2049 outState.putString("apps_customize_currentTab", currentTabTag);
2050 }
2051 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2052 outState.putInt("apps_customize_currentIndex", currentIndex);
2053 }
2054 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
2055 }
2056
2057 @Override
2058 public void onDestroy() {
2059 super.onDestroy();
2060
2061 // Remove all pending runnables
2062 mHandler.removeMessages(ADVANCE_MSG);
2063 mHandler.removeMessages(0);
2064 mWorkspace.removeCallbacks(mBuildLayersRunnable);
2065
2066 // Stop callbacks from LauncherModel
2067 LauncherAppState app = (LauncherAppState.getInstance());
2068
2069 // It's possible to receive onDestroy after a new Launcher activity has
2070 // been created. In this case, don't interfere with the new Launcher.
2071 if (mModel.isCurrentCallbacks(this)) {
2072 mModel.stopLoader();
2073 app.setLauncher(null);
2074 }
2075
2076 try {
2077 mAppWidgetHost.stopListening();
2078 } catch (NullPointerException ex) {
2079 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
2080 }
2081 mAppWidgetHost = null;
2082
2083 mWidgetsToAdvance.clear();
2084
2085 TextKeyListener.getInstance().release();
2086
2087 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2088 // to prevent leaking Launcher activities on orientation change.
2089 if (mModel != null) {
2090 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2091 }
2092
2093 getContentResolver().unregisterContentObserver(mWidgetObserver);
2094 unregisterReceiver(mCloseSystemDialogsReceiver);
2095
2096 mDragLayer.clearAllResizeFrames();
2097 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
2098 mWorkspace.removeAllWorkspaceScreens();
2099 mWorkspace = null;
2100 mDragController = null;
2101
2102 PackageInstallerCompat.getInstance(this).onStop();
2103 LauncherAnimUtils.onDestroyActivity();
2104 }
2105
2106 public DragController getDragController() {
2107 return mDragController;
2108 }
2109
2110 @Override
2111 public void startActivityForResult(Intent intent, int requestCode) {
2112 if (requestCode >= 0) {
2113 setWaitingForResult(true);
2114 }
2115 super.startActivityForResult(intent, requestCode);
2116 }
2117
2118 /**
2119 * Indicates that we want global search for this activity by setting the globalSearch
2120 * argument for {@link #startSearch} to true.
2121 */
2122 @Override
2123 public void startSearch(String initialQuery, boolean selectInitialQuery,
2124 Bundle appSearchData, boolean globalSearch) {
2125
2126 showWorkspace(true);
2127
2128 if (initialQuery == null) {
2129 // Use any text typed in the launcher as the initial query
2130 initialQuery = getTypedText();
2131 }
2132 if (appSearchData == null) {
2133 appSearchData = new Bundle();
2134 appSearchData.putString("source", "launcher-search");
2135 }
2136 Rect sourceBounds = new Rect();
2137 if (mSearchDropTargetBar != null) {
2138 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2139 }
2140
2141 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
2142 appSearchData, sourceBounds);
2143 if (clearTextImmediately) {
2144 clearTypedText();
2145 }
2146 }
2147
2148 /**
2149 * Start a text search.
2150 *
2151 * @return {@code true} if the search will start immediately, so any further keypresses
2152 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2153 * to buffer keypresses.
2154 */
2155 public boolean startSearch(String initialQuery,
2156 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2157 startGlobalSearch(initialQuery, selectInitialQuery,
2158 appSearchData, sourceBounds);
2159 return false;
2160 }
2161
2162 /**
2163 * Starts the global search activity. This code is a copied from SearchManager
2164 */
2165 private void startGlobalSearch(String initialQuery,
2166 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2167 final SearchManager searchManager =
2168 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2169 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2170 if (globalSearchActivity == null) {
2171 Log.w(TAG, "No global search activity found.");
2172 return;
2173 }
2174 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2175 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2176 intent.setComponent(globalSearchActivity);
2177 // Make sure that we have a Bundle to put source in
2178 if (appSearchData == null) {
2179 appSearchData = new Bundle();
2180 } else {
2181 appSearchData = new Bundle(appSearchData);
2182 }
2183 // Set source to package name of app that starts global search, if not set already.
2184 if (!appSearchData.containsKey("source")) {
2185 appSearchData.putString("source", getPackageName());
2186 }
2187 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2188 if (!TextUtils.isEmpty(initialQuery)) {
2189 intent.putExtra(SearchManager.QUERY, initialQuery);
2190 }
2191 if (selectInitialQuery) {
2192 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2193 }
2194 intent.setSourceBounds(sourceBounds);
2195 try {
2196 startActivity(intent);
2197 } catch (ActivityNotFoundException ex) {
2198 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2199 }
2200 }
2201
2202 public boolean isOnCustomContent() {
2203 return mWorkspace.isOnOrMovingToCustomContent();
2204 }
2205
2206 @Override
2207 public boolean onPrepareOptionsMenu(Menu menu) {
2208 super.onPrepareOptionsMenu(menu);
2209 if (!isOnCustomContent()) {
2210 // Close any open folders
2211 closeFolder();
2212 // Stop resizing any widgets
2213 mWorkspace.exitWidgetResizeMode();
2214 if (!mWorkspace.isInOverviewMode()) {
2215 // Show the overview mode
2216 showOverviewMode(true);
2217 } else {
2218 showWorkspace(true);
2219 }
2220 }
2221 return false;
2222 }
2223
2224 @Override
2225 public boolean onSearchRequested() {
2226 startSearch(null, false, null, true);
2227 // Use a custom animation for launching search
2228 return true;
2229 }
2230
2231 public boolean isWorkspaceLocked() {
2232 return mWorkspaceLoading || mWaitingForResult;
2233 }
2234
2235 public boolean isWorkspaceLoading() {
2236 return mWorkspaceLoading;
2237 }
2238
2239 private void setWorkspaceLoading(boolean value) {
2240 boolean isLocked = isWorkspaceLocked();
2241 mWorkspaceLoading = value;
2242 if (isLocked != isWorkspaceLocked()) {
2243 onWorkspaceLockedChanged();
2244 }
2245 }
2246
2247 private void setWaitingForResult(boolean value) {
2248 boolean isLocked = isWorkspaceLocked();
2249 mWaitingForResult = value;
2250 if (isLocked != isWorkspaceLocked()) {
2251 onWorkspaceLockedChanged();
2252 }
2253 }
2254
2255 protected void onWorkspaceLockedChanged() { }
2256
2257 private void resetAddInfo() {
2258 mPendingAddInfo.container = ItemInfo.NO_ID;
2259 mPendingAddInfo.screenId = -1;
2260 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2261 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
2262 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
2263 mPendingAddInfo.dropPos = null;
2264 }
2265
2266 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2267 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2268 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2269 }
2270
2271 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2272 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2273 delay) {
2274 if (appWidgetInfo.configure != null) {
2275 mPendingAddWidgetInfo = appWidgetInfo;
2276 mPendingAddWidgetId = appWidgetId;
2277
2278 // Launch over to configure widget, if needed
2279 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2280 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2281
2282 } else {
2283 // Otherwise just add it
2284 Runnable onComplete = new Runnable() {
2285 @Override
2286 public void run() {
2287 // Exit spring loaded mode if necessary after adding the widget
2288 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2289 null);
2290 }
2291 };
2292 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
2293 appWidgetInfo);
2294 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
2295 }
2296 }
2297
2298 protected void moveToCustomContentScreen(boolean animate) {
2299 // Close any folders that may be open.
2300 closeFolder();
2301 mWorkspace.moveToCustomContentScreen(animate);
2302 }
2303 /**
2304 * Process a shortcut drop.
2305 *
2306 * @param componentName The name of the component
2307 * @param screenId The ID of the screen where it should be added
2308 * @param cell The cell it should be added to, optional
2309 * @param position The location on the screen where it was dropped, optional
2310 */
2311 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2312 int[] cell, int[] loc) {
2313 resetAddInfo();
2314 mPendingAddInfo.container = container;
2315 mPendingAddInfo.screenId = screenId;
2316 mPendingAddInfo.dropPos = loc;
2317
2318 if (cell != null) {
2319 mPendingAddInfo.cellX = cell[0];
2320 mPendingAddInfo.cellY = cell[1];
2321 }
2322
2323 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2324 createShortcutIntent.setComponent(componentName);
2325 processShortcut(createShortcutIntent);
2326 }
2327
2328 /**
2329 * Process a widget drop.
2330 *
2331 * @param info The PendingAppWidgetInfo of the widget being added.
2332 * @param screenId The ID of the screen where it should be added
2333 * @param cell The cell it should be added to, optional
2334 * @param position The location on the screen where it was dropped, optional
2335 */
2336 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2337 int[] cell, int[] span, int[] loc) {
2338 resetAddInfo();
2339 mPendingAddInfo.container = info.container = container;
2340 mPendingAddInfo.screenId = info.screenId = screenId;
2341 mPendingAddInfo.dropPos = loc;
2342 mPendingAddInfo.minSpanX = info.minSpanX;
2343 mPendingAddInfo.minSpanY = info.minSpanY;
2344
2345 if (cell != null) {
2346 mPendingAddInfo.cellX = cell[0];
2347 mPendingAddInfo.cellY = cell[1];
2348 }
2349 if (span != null) {
2350 mPendingAddInfo.spanX = span[0];
2351 mPendingAddInfo.spanY = span[1];
2352 }
2353
2354 AppWidgetHostView hostView = info.boundWidget;
2355 int appWidgetId;
2356 if (hostView != null) {
2357 appWidgetId = hostView.getAppWidgetId();
2358 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
2359 } else {
2360 // In this case, we either need to start an activity to get permission to bind
2361 // the widget, or we need to start an activity to configure the widget, or both.
2362 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
2363 Bundle options = info.bindOptions;
2364
2365 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2366 appWidgetId, info.info, options);
2367 if (success) {
2368 addAppWidgetImpl(appWidgetId, info, null, info.info);
2369 } else {
2370 mPendingAddWidgetInfo = info.info;
2371 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2372 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2373 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
2374 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2375 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
2376 // TODO: we need to make sure that this accounts for the options bundle.
2377 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
2378 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2379 }
2380 }
2381 }
2382
2383 void processShortcut(Intent intent) {
2384 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
2385 }
2386
2387 void processWallpaper(Intent intent) {
2388 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2389 }
2390
2391 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
2392 int cellY) {
2393 final FolderInfo folderInfo = new FolderInfo();
2394 folderInfo.title = getText(R.string.folder_name);
2395
2396 // Update the model
2397 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
2398 false);
2399 sFolders.put(folderInfo.id, folderInfo);
2400
2401 // Create the view
2402 FolderIcon newFolder =
2403 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
2404 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
2405 isWorkspaceLocked());
2406 // Force measure the new folder icon
2407 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2408 parent.getShortcutsAndWidgets().measureChild(newFolder);
2409 return newFolder;
2410 }
2411
2412 void removeFolder(FolderInfo folder) {
2413 sFolders.remove(folder.id);
2414 }
2415
2416 protected ComponentName getWallpaperPickerComponent() {
2417 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
2418 }
2419
2420 /**
2421 * Registers various content observers. The current implementation registers
2422 * only a favorites observer to keep track of the favorites applications.
2423 */
2424 private void registerContentObservers() {
2425 ContentResolver resolver = getContentResolver();
2426 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2427 true, mWidgetObserver);
2428 }
2429
2430 @Override
2431 public boolean dispatchKeyEvent(KeyEvent event) {
2432 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2433 switch (event.getKeyCode()) {
2434 case KeyEvent.KEYCODE_HOME:
2435 return true;
2436 case KeyEvent.KEYCODE_VOLUME_DOWN:
2437 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
2438 dumpState();
2439 return true;
2440 }
2441 break;
2442 }
2443 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2444 switch (event.getKeyCode()) {
2445 case KeyEvent.KEYCODE_HOME:
2446 return true;
2447 }
2448 }
2449
2450 return super.dispatchKeyEvent(event);
2451 }
2452
2453 @Override
2454 public void onBackPressed() {
2455 if (isAllAppsVisible()) {
2456 if (mAppsCustomizeContent.getContentType() ==
2457 AppsCustomizePagedView.ContentType.Applications) {
2458 showWorkspace(true);
2459 } else {
2460 showOverviewMode(true);
2461 }
2462 } else if (mWorkspace.isInOverviewMode()) {
2463 mWorkspace.exitOverviewMode(true);
2464 } else if (mWorkspace.getOpenFolder() != null) {
2465 Folder openFolder = mWorkspace.getOpenFolder();
2466 if (openFolder.isEditingName()) {
2467 openFolder.dismissEditingName();
2468 } else {
2469 closeFolder();
2470 }
2471 } else {
2472 mWorkspace.exitWidgetResizeMode();
2473
2474 // Back button is a no-op here, but give at least some feedback for the button press
2475 mWorkspace.showOutlinesTemporarily();
2476 }
2477 }
2478
2479 /**
2480 * Re-listen when widgets are reset.
2481 */
2482 private void onAppWidgetReset() {
2483 if (mAppWidgetHost != null) {
2484 mAppWidgetHost.startListening();
2485 }
2486 }
2487
2488 /**
2489 * Launches the intent referred by the clicked shortcut.
2490 *
2491 * @param v The view representing the clicked shortcut.
2492 */
2493 public void onClick(View v) {
2494 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2495 // view has detached (it's possible for this to happen if the view is removed mid touch).
2496 if (v.getWindowToken() == null) {
2497 return;
2498 }
2499
2500 if (!mWorkspace.isFinishedSwitchingState()) {
2501 return;
2502 }
2503
2504 if (v instanceof Workspace) {
2505 if (mWorkspace.isInOverviewMode()) {
2506 mWorkspace.exitOverviewMode(true);
2507 }
2508 return;
2509 }
2510
2511 if (v instanceof CellLayout) {
2512 if (mWorkspace.isInOverviewMode()) {
2513 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
2514 }
2515 }
2516
2517 Object tag = v.getTag();
2518 if (tag instanceof ShortcutInfo) {
2519 onClickAppShortcut(v);
2520 } else if (tag instanceof FolderInfo) {
2521 if (v instanceof FolderIcon) {
2522 onClickFolderIcon(v);
2523 }
2524 } else if (v == mAllAppsButton) {
2525 onClickAllAppsButton(v);
2526 } else if (tag instanceof AppInfo) {
2527 startAppShortcutOrInfoActivity(v);
2528 } else if (tag instanceof LauncherAppWidgetInfo) {
2529 if (v instanceof PendingAppWidgetHostView) {
2530 onClickPendingWidget((PendingAppWidgetHostView) v);
2531 }
2532 }
2533 }
2534
2535 public void onClickPagedViewIcon(View v) {
2536 startAppShortcutOrInfoActivity(v);
2537 }
2538
2539 public boolean onTouch(View v, MotionEvent event) {
2540 return false;
2541 }
2542
2543 /**
2544 * Event handler for the app widget view which has not fully restored.
2545 */
2546 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2547 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2548 if (v.isReadyForClickSetup()) {
2549 int widgetId = info.appWidgetId;
2550 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2551 if (appWidgetInfo != null) {
2552 mPendingAddWidgetInfo = appWidgetInfo;
2553 mPendingAddInfo.copyFrom(info);
2554 mPendingAddWidgetId = widgetId;
2555
2556 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2557 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
2558 }
2559 } else if (info.installProgress < 0) {
2560 // The install has not been queued
2561 final String packageName = info.providerName.getPackageName();
2562 showBrokenAppInstallDialog(packageName,
2563 new DialogInterface.OnClickListener() {
2564 public void onClick(DialogInterface dialog, int id) {
2565 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2566 }
2567 });
2568 } else {
2569 // Download has started.
2570 final String packageName = info.providerName.getPackageName();
2571 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2572 }
2573 }
2574
2575 /**
2576 * Event handler for the search button
2577 *
2578 * @param v The view that was clicked.
2579 */
2580 public void onClickSearchButton(View v) {
2581 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2582
2583 onSearchRequested();
2584 }
2585
2586 /**
2587 * Event handler for the voice button
2588 *
2589 * @param v The view that was clicked.
2590 */
2591 public void onClickVoiceButton(View v) {
2592 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2593
2594 startVoice();
2595 }
2596
2597 public void startVoice() {
2598 try {
2599 final SearchManager searchManager =
2600 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2601 ComponentName activityName = searchManager.getGlobalSearchActivity();
2602 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2603 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2604 if (activityName != null) {
2605 intent.setPackage(activityName.getPackageName());
2606 }
2607 startActivity(null, intent, "onClickVoiceButton");
2608 } catch (ActivityNotFoundException e) {
2609 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2610 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2611 startActivitySafely(null, intent, "onClickVoiceButton");
2612 }
2613 }
2614
2615 /**
2616 * Event handler for the "grid" button that appears on the home screen, which
2617 * enters all apps mode.
2618 *
2619 * @param v The view that was clicked.
2620 */
2621 protected void onClickAllAppsButton(View v) {
2622 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2623 if (isAllAppsVisible()) {
2624 showWorkspace(true);
2625 } else {
2626 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2627 }
2628 }
2629
2630 private void showBrokenAppInstallDialog(final String packageName,
2631 DialogInterface.OnClickListener onSearchClickListener) {
2632 new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault))
2633 .setTitle(R.string.abandoned_promises_title)
2634 .setMessage(R.string.abandoned_promise_explanation)
2635 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2636 .setNeutralButton(R.string.abandoned_clean_this,
2637 new DialogInterface.OnClickListener() {
2638 public void onClick(DialogInterface dialog, int id) {
2639 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2640 mWorkspace.removeAbandonedPromise(packageName, user);
2641 }
2642 })
2643 .create().show();
2644 return;
2645 }
2646
2647 /**
2648 * Event handler for an app shortcut click.
2649 *
2650 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2651 */
2652 protected void onClickAppShortcut(final View v) {
2653 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2654 Object tag = v.getTag();
2655 if (!(tag instanceof ShortcutInfo)) {
2656 throw new IllegalArgumentException("Input must be a Shortcut");
2657 }
2658
2659 // Open shortcut
2660 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2661 final Intent intent = shortcut.intent;
2662
2663 // Check for special shortcuts
2664 if (intent.getComponent() != null) {
2665 final String shortcutClass = intent.getComponent().getClassName();
2666
2667 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2668 MemoryDumpActivity.startDump(this);
2669 return;
2670 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2671 toggleShowWeightWatcher();
2672 return;
2673 }
2674 }
2675
2676 // Check for abandoned promise
2677 if ((v instanceof BubbleTextView)
2678 && shortcut.isPromise()
2679 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
2680 showBrokenAppInstallDialog(
2681 shortcut.getTargetComponent().getPackageName(),
2682 new DialogInterface.OnClickListener() {
2683 public void onClick(DialogInterface dialog, int id) {
2684 startAppShortcutOrInfoActivity(v);
2685 }
2686 });
2687 return;
2688 }
2689
2690 // Start activities
2691 startAppShortcutOrInfoActivity(v);
2692 }
2693
2694 private void startAppShortcutOrInfoActivity(View v) {
2695 Object tag = v.getTag();
2696 final ShortcutInfo shortcut;
2697 final Intent intent;
2698 if (tag instanceof ShortcutInfo) {
2699 shortcut = (ShortcutInfo) tag;
2700 intent = shortcut.intent;
2701 int[] pos = new int[2];
2702 v.getLocationOnScreen(pos);
2703 intent.setSourceBounds(new Rect(pos[0], pos[1],
2704 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2705
2706 } else if (tag instanceof AppInfo) {
2707 shortcut = null;
2708 intent = ((AppInfo) tag).intent;
2709 } else {
2710 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2711 }
2712
2713 boolean success = startActivitySafely(v, intent, tag);
2714 mStats.recordLaunch(intent, shortcut);
2715
2716 if (success && v instanceof BubbleTextView) {
2717 mWaitingForResume = (BubbleTextView) v;
2718 mWaitingForResume.setStayPressed(true);
2719 }
2720 }
2721
2722 /**
2723 * Event handler for a folder icon click.
2724 *
2725 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2726 */
2727 protected void onClickFolderIcon(View v) {
2728 if (LOGD) Log.d(TAG, "onClickFolder");
2729 if (!(v instanceof FolderIcon)){
2730 throw new IllegalArgumentException("Input must be a FolderIcon");
2731 }
2732
2733 FolderIcon folderIcon = (FolderIcon) v;
2734 final FolderInfo info = folderIcon.getFolderInfo();
2735 Folder openFolder = mWorkspace.getFolderForTag(info);
2736
2737 // If the folder info reports that the associated folder is open, then verify that
2738 // it is actually opened. There have been a few instances where this gets out of sync.
2739 if (info.opened && openFolder == null) {
2740 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2741 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2742 info.opened = false;
2743 }
2744
2745 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2746 // Close any open folder
2747 closeFolder();
2748 // Open the requested folder
2749 openFolder(folderIcon);
2750 } else {
2751 // Find the open folder...
2752 int folderScreen;
2753 if (openFolder != null) {
2754 folderScreen = mWorkspace.getPageForView(openFolder);
2755 // .. and close it
2756 closeFolder(openFolder);
2757 if (folderScreen != mWorkspace.getCurrentPage()) {
2758 // Close any folder open on the current screen
2759 closeFolder();
2760 // Pull the folder onto this screen
2761 openFolder(folderIcon);
2762 }
2763 }
2764 }
2765 }
2766
2767 /**
2768 * Event handler for the (Add) Widgets button that appears after a long press
2769 * on the home screen.
2770 */
2771 protected void onClickAddWidgetButton(View view) {
2772 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
2773 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2774 }
2775
2776 /**
2777 * Event handler for the wallpaper picker button that appears after a long press
2778 * on the home screen.
2779 */
2780 protected void onClickWallpaperPicker(View v) {
2781 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2782 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2783 pickWallpaper.setComponent(getWallpaperPickerComponent());
2784 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2785 }
2786
2787 /**
2788 * Event handler for a click on the settings button that appears after a long press
2789 * on the home screen.
2790 */
2791 protected void onClickSettingsButton(View v) {
2792 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2793 }
2794
2795 public void onTouchDownAllAppsButton(View v) {
2796 // Provide the same haptic feedback that the system offers for virtual keys.
2797 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2798 }
2799
2800 public void performHapticFeedbackOnTouchDown(View v) {
2801 // Provide the same haptic feedback that the system offers for virtual keys.
2802 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2803 }
2804
2805 public View.OnTouchListener getHapticFeedbackTouchListener() {
2806 if (mHapticFeedbackTouchListener == null) {
2807 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2808 @Override
2809 public boolean onTouch(View v, MotionEvent event) {
2810 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2811 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2812 }
2813 return false;
2814 }
2815 };
2816 }
2817 return mHapticFeedbackTouchListener;
2818 }
2819
2820 public void onDragStarted(View view) {}
2821
2822 /**
2823 * Called when the user stops interacting with the launcher.
2824 * This implies that the user is now on the homescreen and is not doing housekeeping.
2825 */
2826 protected void onInteractionEnd() {}
2827
2828 /**
2829 * Called when the user starts interacting with the launcher.
2830 * The possible interactions are:
2831 * - open all apps
2832 * - reorder an app shortcut, or a widget
2833 * - open the overview mode.
2834 * This is a good time to stop doing things that only make sense
2835 * when the user is on the homescreen and not doing housekeeping.
2836 */
2837 protected void onInteractionBegin() {}
2838
2839 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
2840 String packageName = componentName.getPackageName();
2841 try {
2842 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2843 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2844 launcherApps.showAppDetailsForProfile(componentName, user);
2845 } catch (SecurityException e) {
2846 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2847 Log.e(TAG, "Launcher does not have permission to launch settings");
2848 } catch (ActivityNotFoundException e) {
2849 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2850 Log.e(TAG, "Unable to launch settings");
2851 }
2852 }
2853
2854 // returns true if the activity was started
2855 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2856 UserHandleCompat user) {
2857 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
2858 // System applications cannot be installed. For now, show a toast explaining that.
2859 // We may give them the option of disabling apps this way.
2860 int messageId = R.string.uninstall_system_app_text;
2861 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2862 return false;
2863 } else {
2864 String packageName = componentName.getPackageName();
2865 String className = componentName.getClassName();
2866 Intent intent = new Intent(
2867 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2868 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2869 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
2870 if (user != null) {
2871 user.addToIntent(intent, Intent.EXTRA_USER);
2872 }
2873 startActivity(intent);
2874 return true;
2875 }
2876 }
2877
2878 boolean startActivity(View v, Intent intent, Object tag) {
2879 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2880 try {
2881 // Only launch using the new animation if the shortcut has not opted out (this is a
2882 // private contract between launcher and may be ignored in the future).
2883 boolean useLaunchAnimation = (v != null) &&
2884 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2885 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2886 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2887
2888 UserHandleCompat user = null;
2889 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2890 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2891 user = userManager.getUserForSerialNumber(serialNumber);
2892 }
2893
2894 Bundle optsBundle = null;
2895 if (useLaunchAnimation) {
2896 ActivityOptions opts = Utilities.isLmpOrAbove() ?
2897 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim)🔵
2898 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasured🔵
2899 optsBundle = opts.toBundle();
2900 }
2901
2902 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2903 // Could be launching some bookkeeping activity
2904 startActivity(intent, optsBundle);
2905 } else {
2906 // TODO Component can be null when shortcuts are supported for secondary user
2907 launcherApps.startActivityForProfile(intent.getComponent(), user,
2908 intent.getSourceBounds(), optsBundle);
2909 }
2910 return true;
2911 } catch (SecurityException e) {
2912 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2913 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2914 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2915 "or use the exported attribute for this activity. "
2916 + "tag="+ tag + " intent=" + intent, e);
2917 }
2918 return false;
2919 }
2920
2921 boolean startActivitySafely(View v, Intent intent, Object tag) {
2922 boolean success = false;
2923 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2924 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2925 return false;
2926 }
2927 try {
2928 success = startActivity(v, intent, tag);
2929 } catch (ActivityNotFoundException e) {
2930 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2931 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2932 }
2933 return success;
2934 }
2935
2936 /**
2937 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2938 * in the DragLayer in the exact absolute location of the original FolderIcon.
2939 */
2940 private void copyFolderIconToImage(FolderIcon fi) {
2941 final int width = fi.getMeasuredWidth();
2942 final int height = fi.getMeasuredHeight();
2943
2944 // Lazy load ImageView, Bitmap and Canvas
2945 if (mFolderIconImageView == null) {
2946 mFolderIconImageView = new ImageView(this);
2947 }
2948 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2949 mFolderIconBitmap.getHeight() != height) {
2950 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2951 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2952 }
2953
2954 DragLayer.LayoutParams lp;
2955 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2956 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2957 } else {
2958 lp = new DragLayer.LayoutParams(width, height);
2959 }
2960
2961 // The layout from which the folder is being opened may be scaled, adjust the starting
2962 // view size by this scale factor.
2963 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
2964 lp.customPosition = true;
2965 lp.x = mRectForFolderAnimation.left;
2966 lp.y = mRectForFolderAnimation.top;
2967 lp.width = (int) (scale * width);
2968 lp.height = (int) (scale * height);
2969
2970 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
2971 fi.draw(mFolderIconCanvas);
2972 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
2973 if (fi.getFolder() != null) {
2974 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
2975 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
2976 }
2977 // Just in case this image view is still in the drag layer from a previous animation,
2978 // we remove it and re-add it.
2979 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
2980 mDragLayer.removeView(mFolderIconImageView);
2981 }
2982 mDragLayer.addView(mFolderIconImageView, lp);
2983 if (fi.getFolder() != null) {
2984 fi.getFolder().bringToFront();
2985 }
2986 }
2987
2988 private void growAndFadeOutFolderIcon(FolderIcon fi) {
2989 if (fi == null) return;
2990 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
2991 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
2992 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
2993
2994 FolderInfo info = (FolderInfo) fi.getTag();
2995 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
2996 CellLayout cl = (CellLayout) fi.getParent().getParent();
2997 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
2998 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
2999 }
3000
3001 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3002 copyFolderIconToImage(fi);
3003 fi.setVisibility(View.INVISIBLE);
3004
3005 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
3006 scaleX, scaleY);
3007 if (Utilities.isLmpOrAbove()) {
3008 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3009 }
3010 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
3011 oa.start();
3012 }
3013
3014 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
3015 if (fi == null) return;
3016 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3017 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3018 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3019
3020 final CellLayout cl = (CellLayout) fi.getParent().getParent();
3021
3022 // We remove and re-draw the FolderIcon in-case it has changed
3023 mDragLayer.removeView(mFolderIconImageView);
3024 copyFolderIconToImage(fi);
3025 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
3026 scaleX, scaleY);
3027 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
3028 oa.addListener(new AnimatorListenerAdapter() {
3029 @Override
3030 public void onAnimationEnd(Animator animation) {
3031 if (cl != null) {
3032 cl.clearFolderLeaveBehind();
3033 // Remove the ImageView copy of the FolderIcon and make the original visible.
3034 mDragLayer.removeView(mFolderIconImageView);
3035 fi.setVisibility(View.VISIBLE);
3036 }
3037 }
3038 });
3039 oa.start();
3040 }
3041
3042 /**
3043 * Opens the user folder described by the specified tag. The opening of the folder
3044 * is animated relative to the specified View. If the View is null, no animation
3045 * is played.
3046 *
3047 * @param folderInfo The FolderInfo describing the folder to open.
3048 */
3049 public void openFolder(FolderIcon folderIcon) {
3050 Folder folder = folderIcon.getFolder();
3051 FolderInfo info = folder.mInfo;
3052
3053 info.opened = true;
3054
3055 // Just verify that the folder hasn't already been added to the DragLayer.
3056 // There was a one-off crash where the folder had a parent already.
3057 if (folder.getParent() == null) {
3058 mDragLayer.addView(folder);
3059 mDragController.addDropTarget((DropTarget) folder);
3060 } else {
3061 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3062 folder.getParent() + ").");
3063 }
3064 folder.animateOpen();
3065 growAndFadeOutFolderIcon(folderIcon);
3066
3067 // Notify the accessibility manager that this folder "window" has appeared and occluded
3068 // the workspace items
3069 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3070 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
3071 }
3072
3073 public void closeFolder() {
3074 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3075 if (folder != null) {
3076 if (folder.isEditingName()) {
3077 folder.dismissEditingName();
3078 }
3079 closeFolder(folder);
3080 <<<<<<< MINE
3081 ||||||| BASE
3082
3083 // Dismiss the folder cling
3084 dismissFolderCling(null);
3085 =======
3086
3087 // Dismiss the folder cling
3088 mLauncherClings.dismissFolderCling(null);
3089 >>>>>>> YOURS
3090 }
3091 }
3092
3093 void closeFolder(Folder folder) {
3094 folder.getInfo().opened = false;
3095
3096 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3097 if (parent != null) {
3098 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3099 shrinkAndFadeInFolderIcon(fi);
3100 }
3101 folder.animateClosed();
3102
3103 // Notify the accessibility manager that this folder "window" has disappeard and no
3104 // longer occludeds the workspace items
3105 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3106 }
3107
3108 public boolean onLongClick(View v) {
3109 if (!isDraggingEnabled()) return false;
3110 if (isWorkspaceLocked()) return false;
3111 if (mState != State.WORKSPACE) return false;
3112
3113 if (v instanceof Workspace) {
3114 if (!mWorkspace.isInOverviewMode()) {
3115 if (mWorkspace.enterOverviewMode()) {
3116 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3117 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3118 return true;
3119 } else {
3120 return false;
3121 }
3122 } else {
3123 return false;
3124 }
3125 }
3126
3127 CellLayout.CellInfo longClickCellInfo = null;
3128 View itemUnderLongClick = null;
3129 if (v.getTag() instanceof ItemInfo) {
3130 ItemInfo info = (ItemInfo) v.getTag();
3131 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3132 itemUnderLongClick = longClickCellInfo.cell;
3133 resetAddInfo();
3134 }
3135
3136 // The hotseat touch handling does not go through Workspace, and we always allow long press
3137 // on hotseat items.
3138 final boolean inHotseat = isHotseatLayout(v);
3139 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
3140 if (allowLongPress && !mDragController.isDragging()) {
3141 if (itemUnderLongClick == null) {
3142 // User long pressed on empty space
3143 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3144 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3145 if (mWorkspace.isInOverviewMode()) {
3146 mWorkspace.startReordering(v);
3147 } else {
3148 mWorkspace.enterOverviewMode();
3149 }
3150 } else {
3151 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3152 mHotseat.getOrderInHotseat(
3153 longClickCellInfo.cellX,
3154 longClickCellInfo.cellY));
3155 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
3156 // User long pressed on an item
3157 mWorkspace.startDrag(longClickCellInfo);
3158 }
3159 }
3160 }
3161 return true;
3162 }
3163
3164 boolean isHotseatLayout(View layout) {
3165 return mHotseat != null && layout != null &&
3166 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3167 }
3168
3169 /**
3170 * Returns the CellLayout of the specified container at the specified screen.
3171 */
3172 CellLayout getCellLayout(long container, long screenId) {
3173 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3174 if (mHotseat != null) {
3175 return mHotseat.getLayout();
3176 } else {
3177 return null;
3178 }
3179 } else {
3180 return (CellLayout) mWorkspace.getScreenWithId(screenId);
3181 }
3182 }
3183
3184 public boolean isAllAppsVisible() {
3185 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
3186 }
3187
3188 private void setWorkspaceBackground(boolean workspace) {
3189 mLauncherView.setBackground(workspace ?
3190 mWorkspaceBackgroundDrawable : null);
3191 }
3192
3193 protected void changeWallpaperVisiblity(boolean visible) {
3194 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3195 int curflags = getWindow().getAttributes().flags
3196 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3197 if (wpflags != curflags) {
3198 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3199 }
3200 setWorkspaceBackground(visible);
3201 }
3202
3203 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3204 if (v instanceof LauncherTransitionable) {
3205 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3206 }
3207 }
3208
3209 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3210 if (v instanceof LauncherTransitionable) {
3211 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3212 }
3213
3214 // Update the workspace transition step as well
3215 dispatchOnLauncherTransitionStep(v, 0f);
3216 }
3217
3218 private void dispatchOnLauncherTransitionStep(View v, float t) {
3219 if (v instanceof LauncherTransitionable) {
3220 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3221 }
3222 }
3223
3224 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3225 if (v instanceof LauncherTransitionable) {
3226 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3227 }
3228
3229 // Update the workspace transition step as well
3230 dispatchOnLauncherTransitionStep(v, 1f);
3231 }
3232
3233 /**
3234 * Things to test when changing the following seven functions.
3235 * - Home from workspace
3236 * - from center screen
3237 * - from other screens
3238 * - Home from all apps
3239 * - from center screen
3240 * - from other screens
3241 * - Back from all apps
3242 * - from center screen
3243 * - from other screens
3244 * - Launch app from workspace and quit
3245 * - with back
3246 * - with home
3247 * - Launch app from all apps and quit
3248 * - with back
3249 * - with home
3250 * - Go to a screen that's not the default, then all
3251 * apps, and launch and app, and go back
3252 * - with back
3253 * -with home
3254 * - On workspace, long press power and go back
3255 * - with back
3256 * - with home
3257 * - On all apps, long press power and go back
3258 * - with back
3259 * - with home
3260 * - On workspace, power off
3261 * - On all apps, power off
3262 * - Launch an app and turn off the screen while in that app
3263 * - Go back with home key
3264 * - Go back with back key TODO: make this not go to workspace
3265 * - From all apps
3266 * - From workspace
3267 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3268 * - From all apps
3269 * - From the center workspace
3270 * - From another workspace
3271 */
3272
3273 /**
3274 * Zoom the camera out from the workspace to reveal 'toView'.
3275 * Assumes that the view to show is anchored at either the very top or very bottom
3276 * of the screen.
3277 */
3278 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
3279 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3280 showAppsCustomizeHelper(animated, springLoaded, contentType);
3281 }
3282
3283 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3284 final AppsCustomizePagedView.ContentType contentType) {
3285 if (mStateAnimation != null) {
3286 mStateAnimation.setDuration(0);
3287 mStateAnimation.cancel();
3288 mStateAnimation = null;
3289 }
3290
3291 boolean material = Utilities.isLmpOrAbove();
3292
3293 final Resources res = getResources();
3294
3295 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3296 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3297 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
3298 final int itemsAlphaStagger =
3299 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3300
3301 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3302 final View fromView = mWorkspace;
3303 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
3304
3305 final ArrayList<View> layerViews = new ArrayList<View>();
3306
3307 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3308 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
3309 Animator workspaceAnim =
3310 <<<<<<< MINE
3311 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
3312 ||||||| BASE
3313 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
3314 if (!AppsCustomizePagedView.DISABLE_ALL_APPS
3315 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3316 // Set the content type for the all apps/widgets space
3317 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3318 }
3319
3320 =======
3321 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
3322 >>>>>>> YOURS
3323 if (!LauncherAppState.isDisableAllApps()
3324 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3325 // Set the content type for the all apps/widgets space
3326 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3327 }
3328
3329 // If for some reason our views aren't initialized, don't animate
3330 boolean initialized = getAllAppsButton() != null;
3331
3332 if (animated && initialized) {
3333 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3334 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3335 toView.findViewById(R.id.apps_customize_pane_content);
3336
3337 final View page = content.getPageAt(content.getCurrentPage());
3338 final View revealView = toView.findViewById(R.id.fake_page);
3339
3340 final float initialPanelAlpha = 1f;
3341
3342 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3343 if (isWidgetTray) {
3344 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3345 } else {
3346 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3347 }
3348
3349 // Hide the real page background, and swap in the fake one
3350 content.setPageBackgroundsVisible(false);
3351 revealView.setVisibility(View.VISIBLE);
3352 // We need to hide this view as the animation start will be posted.
3353 revealView.setAlpha(0);
3354
3355 int width = revealView.getMeasuredWidth();
3356 int height = revealView.getMeasuredHeight();
3357 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3358
3359 revealView.setTranslationY(0);
3360 revealView.setTranslationX(0);
3361
3362 // Get the y delta between the center of the page and the center of the all apps button
3363 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3364 getAllAppsButton(), null);
3365
3366 float alpha = 0;
3367 float xDrift = 0;
3368 float yDrift = 0;
3369 if (material) {
3370 alpha = isWidgetTray ? 0.3f : 1f;
3371 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3372 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3373 } else {
3374 yDrift = 2 * height / 3;
3375 xDrift = 0;
3376 }
3377 final float initAlpha = alpha;
3378
3379 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3380 layerViews.add(revealView);
3381 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
3382 PropertyValuesHolder panelDriftY =
3383 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
3384 PropertyValuesHolder panelDriftX =
3385 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
3386
3387 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3388 panelAlpha, panelDriftY, panelDriftX);
3389
3390 panelAlphaAndDrift.setDuration(revealDuration);
3391 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3392
3393 mStateAnimation.play(panelAlphaAndDrift);
3394
3395 if (page != null) {
3396 page.setVisibility(View.VISIBLE);
3397 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3398 layerViews.add(page);
3399
3400 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3401 page.setTranslationY(yDrift);
3402 pageDrift.setDuration(revealDuration);
3403 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3404 pageDrift.setStartDelay(itemsAlphaStagger);
3405 mStateAnimation.play(pageDrift);
3406
3407 page.setAlpha(0f);
3408 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
3409 itemsAlpha.setDuration(revealDuration);
3410 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3411 itemsAlpha.setStartDelay(itemsAlphaStagger);
3412 mStateAnimation.play(itemsAlpha);
3413 }
3414
3415 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3416 pageIndicators.setAlpha(0.01f);
3417 ObjectAnimator indicatorsAlpha =
3418 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
3419 indicatorsAlpha.setDuration(revealDuration);
3420 mStateAnimation.play(indicatorsAlpha);
3421
3422 if (material) {
3423 final View allApps = getAllAppsButton();
3424 int allAppsButtonSize = LauncherAppState.getInstance().
3425 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3426 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3427 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3428 height / 2, startRadius, revealRadius);
3429 reveal.setDuration(revealDuration);
3430 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3431
3432 reveal.addListener(new AnimatorListenerAdapter() {
3433 public void onAnimationStart(Animator animation) {
3434 if (!isWidgetTray) {
3435 allApps.setVisibility(View.INVISIBLE);
3436 }
3437 }
3438 public void onAnimationEnd(Animator animation) {
3439 if (!isWidgetTray) {
3440 allApps.setVisibility(View.VISIBLE);
3441 }
3442 }
3443 });
3444 mStateAnimation.play(reveal);
3445 }
3446
3447 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3448 @Override
3449 public void onAnimationEnd(Animator animation) {
3450 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3451 dispatchOnLauncherTransitionEnd(toView, animated, false);
3452
3453 revealView.setVisibility(View.INVISIBLE);
3454 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3455 if (page != null) {
3456 page.setLayerType(View.LAYER_TYPE_NONE, null);
3457 }
3458 content.setPageBackgroundsVisible(true);
3459
3460 // Hide the search bar
3461 if (mSearchDropTargetBar != null) {
3462 mSearchDropTargetBar.hideSearchBar(false);
3463 }
3464 }
3465
3466 });
3467
3468 if (workspaceAnim != null) {
3469 mStateAnimation.play(workspaceAnim);
3470 }
3471
3472 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3473 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3474 final AnimatorSet stateAnimation = mStateAnimation;
3475 final Runnable startAnimRunnable = new Runnable() {
3476 public void run() {
3477 // Check that mStateAnimation hasn't changed while
3478 // we waited for a layout/draw pass
3479 if (mStateAnimation != stateAnimation)
3480 return;
3481 dispatchOnLauncherTransitionStart(fromView, animated, false);
3482 dispatchOnLauncherTransitionStart(toView, animated, false);
3483
3484 revealView.setAlpha(initAlpha);
3485 if (Utilities.isLmpOrAbove()) {
3486 for (int i = 0; i < layerViews.size(); i++) {
3487 View v = layerViews.get(i);
3488 if (v != null) {
3489 boolean attached = true;
3490 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3491 attached = v.isAttachedToWindow();
3492 }
3493 if (attached) v.buildLayer();
3494 }
3495 }
3496 }
3497 mStateAnimation.start();
3498 }
3499 };
3500 toView.bringToFront();
3501 toView.setVisibility(View.VISIBLE);
3502 toView.post(startAnimRunnable);
3503 } else {
3504 toView.setTranslationX(0.0f);
3505 toView.setTranslationY(0.0f);
3506 toView.setScaleX(1.0f);
3507 toView.setScaleY(1.0f);
3508 toView.setVisibility(View.VISIBLE);
3509 toView.bringToFront();
3510
3511 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
3512 // Hide the search bar
3513 if (mSearchDropTargetBar != null) {
3514 mSearchDropTargetBar.hideSearchBar(false);
3515 }
3516 }
3517 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3518 dispatchOnLauncherTransitionStart(fromView, animated, false);
3519 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3520 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3521 dispatchOnLauncherTransitionStart(toView, animated, false);
3522 dispatchOnLauncherTransitionEnd(toView, animated, false);
3523 }
3524 }
3525
3526 /**
3527 * Zoom the camera back into the workspace, hiding 'fromView'.
3528 * This is the opposite of showAppsCustomizeHelper.
3529 * @param animated If true, the transition will be animated.
3530 */
3531 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
3532 final boolean springLoaded, final Runnable onCompleteRunnable) {
3533
3534 if (mStateAnimation != null) {
3535 mStateAnimation.setDuration(0);
3536 mStateAnimation.cancel();
3537 mStateAnimation = null;
3538 }
3539
3540 boolean material = Utilities.isLmpOrAbove();
3541 Resources res = getResources();
3542
3543 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
3544 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3545 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
3546 final int itemsAlphaStagger =
3547 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3548
3549 final float scaleFactor = (float)
3550 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3551 final View fromView = mAppsCustomizeTabHost;
3552 final View toView = mWorkspace;
3553 Animator workspaceAnim = null;
3554 final ArrayList<View> layerViews = new ArrayList<View>();
3555
3556 if (toState == Workspace.State.NORMAL) {
3557 workspaceAnim = mWorkspace.getChangeStateAnimation(
3558 toState, animated, layerViews);
3559 } else if (toState == Workspace.State.SPRING_LOADED ||
3560 toState == Workspace.State.OVERVIEW) {
3561 workspaceAnim = mWorkspace.getChangeStateAnimation(
3562 toState, animated, layerViews);
3563 }
3564
3565 // If for some reason our views aren't initialized, don't animate
3566 boolean initialized = getAllAppsButton() != null;
3567
3568 if (animated && initialized) {
3569 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3570 if (workspaceAnim != null) {
3571 mStateAnimation.play(workspaceAnim);
3572 }
3573
3574 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3575 fromView.findViewById(R.id.apps_customize_pane_content);
3576
3577 final View page = content.getPageAt(content.getNextPage());
3578
3579 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3580 int count = content.getChildCount();
3581 for (int i = 0; i < count; i++) {
3582 View child = content.getChildAt(i);
3583 if (child != page) {
3584 child.setVisibility(View.INVISIBLE);
3585 }
3586 }
3587 final View revealView = fromView.findViewById(R.id.fake_page);
3588
3589 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3590 // don't perform all these no-op animations. In particularly, this was causing
3591 // the all-apps button to pop in and out.
3592 if (fromView.getVisibility() == View.VISIBLE) {
3593 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3594 final boolean isWidgetTray =
3595 contentType == AppsCustomizePagedView.ContentType.Widgets;
3596
3597 if (isWidgetTray) {
3598 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3599 } else {
3600 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3601 }
3602
3603 int width = revealView.getMeasuredWidth();
3604 int height = revealView.getMeasuredHeight();
3605 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3606
3607 // Hide the real page background, and swap in the fake one
3608 revealView.setVisibility(View.VISIBLE);
3609 content.setPageBackgroundsVisible(false);
3610
3611 final View allAppsButton = getAllAppsButton();
3612 revealView.setTranslationY(0);
3613 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3614 allAppsButton, null);
3615
3616 float xDrift = 0;
3617 float yDrift = 0;
3618 if (material) {
3619 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3620 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3621 } else {
3622 yDrift = 5 * height / 4;
3623 xDrift = 0;
3624 }
3625
3626 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3627 TimeInterpolator decelerateInterpolator = material ?
3628 new LogDecelerateInterpolator(100, 0) :
3629 new LogDecelerateInterpolator(30, 0);
3630
3631 // The vertical motion of the apps panel should be delayed by one frame
3632 // from the conceal animation in order to give the right feel. We correpsondingly
3633 // shorten the duration so that the slide and conceal end at the same time.
3634 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3635 0, yDrift);
3636 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3637 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3638 panelDriftY.setInterpolator(decelerateInterpolator);
3639 mStateAnimation.play(panelDriftY);
3640
3641 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3642 0, xDrift);
3643 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3644 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3645 panelDriftX.setInterpolator(decelerateInterpolator);
3646 mStateAnimation.play(panelDriftX);
3647
3648 if (isWidgetTray || !material) {
3649 float finalAlpha = material ? 0.4f : 0f;
3650 revealView.setAlpha(1f);
3651 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3652 1f, finalAlpha);
3653 panelAlpha.setDuration(revealDuration);
3654 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3655 new AccelerateInterpolator(1.5f));
3656 mStateAnimation.play(panelAlpha);
3657 }
3658
3659 if (page != null) {
3660 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3661
3662 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3663 0, yDrift);
3664 page.setTranslationY(0);
3665 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3666 pageDrift.setInterpolator(decelerateInterpolator);
3667 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3668 mStateAnimation.play(pageDrift);
3669
3670 page.setAlpha(1f);
3671 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3672 itemsAlpha.setDuration(100);
3673 itemsAlpha.setInterpolator(decelerateInterpolator);
3674 mStateAnimation.play(itemsAlpha);
3675 }
3676
3677 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3678 pageIndicators.setAlpha(1f);
3679 ObjectAnimator indicatorsAlpha =
3680 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3681 indicatorsAlpha.setDuration(revealDuration);
3682 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3683 mStateAnimation.play(indicatorsAlpha);
3684
3685 width = revealView.getMeasuredWidth();
3686
3687 if (material) {
3688 if (!isWidgetTray) {
3689 allAppsButton.setVisibility(View.INVISIBLE);
3690 }
3691 int allAppsButtonSize = LauncherAppState.getInstance().
3692 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3693 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3694 Animator reveal =
3695 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3696 height / 2, revealRadius, finalRadius);
3697 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3698 reveal.setDuration(revealDuration);
3699 reveal.setStartDelay(itemsAlphaStagger);
3700
3701 reveal.addListener(new AnimatorListenerAdapter() {
3702 public void onAnimationEnd(Animator animation) {
3703 revealView.setVisibility(View.INVISIBLE);
3704 if (!isWidgetTray) {
3705 allAppsButton.setVisibility(View.VISIBLE);
3706 }
3707 }
3708 });
3709
3710 mStateAnimation.play(reveal);
3711 }
3712
3713 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3714 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3715 mAppsCustomizeContent.stopScrolling();
3716 }
3717
3718 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3719 @Override
3720 public void onAnimationEnd(Animator animation) {
3721 fromView.setVisibility(View.GONE);
3722 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3723 dispatchOnLauncherTransitionEnd(toView, animated, true);
3724 if (onCompleteRunnable != null) {
3725 onCompleteRunnable.run();
3726 }
3727
3728 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3729 if (page != null) {
3730 page.setLayerType(View.LAYER_TYPE_NONE, null);
3731 }
3732 content.setPageBackgroundsVisible(true);
3733 // Unhide side pages
3734 int count = content.getChildCount();
3735 for (int i = 0; i < count; i++) {
3736 View child = content.getChildAt(i);
3737 child.setVisibility(View.VISIBLE);
3738 }
3739
3740 // Reset page transforms
3741 if (page != null) {
3742 page.setTranslationX(0);
3743 page.setTranslationY(0);
3744 page.setAlpha(1);
3745 }
3746 content.setCurrentPage(content.getNextPage());
3747
3748 mAppsCustomizeContent.updateCurrentPageScroll();
3749 }
3750 });
3751
3752 final AnimatorSet stateAnimation = mStateAnimation;
3753 final Runnable startAnimRunnable = new Runnable() {
3754 public void run() {
3755 // Check that mStateAnimation hasn't changed while
3756 // we waited for a layout/draw pass
3757 if (mStateAnimation != stateAnimation)
3758 return;
3759 dispatchOnLauncherTransitionStart(fromView, animated, false);
3760 dispatchOnLauncherTransitionStart(toView, animated, false);
3761
3762 if (Utilities.isLmpOrAbove()) {
3763 for (int i = 0; i < layerViews.size(); i++) {
3764 View v = layerViews.get(i);
3765 if (v != null) {
3766 boolean attached = true;
3767 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3768 attached = v.isAttachedToWindow();
3769 }
3770 if (attached) v.buildLayer();
3771 }
3772 }
3773 }
3774 mStateAnimation.start();
3775 }
3776 };
3777 fromView.post(startAnimRunnable);
3778 } else {
3779 fromView.setVisibility(View.GONE);
3780 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3781 dispatchOnLauncherTransitionStart(fromView, animated, true);
3782 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3783 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3784 dispatchOnLauncherTransitionStart(toView, animated, true);
3785 dispatchOnLauncherTransitionEnd(toView, animated, true);
3786 }
3787 }
3788
3789 @Override
3790 public void onTrimMemory(int level) {
3791 super.onTrimMemory(level);
3792 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
3793 mAppsCustomizeTabHost.onTrimMemory();
3794 }
3795 }
3796
3797 protected void showWorkspace(boolean animated) {
3798 showWorkspace(animated, null);
3799 }
3800
3801 protected void showWorkspace() {
3802 showWorkspace(true);
3803 }
3804
3805 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
3806 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
3807 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
3808 mWorkspace.setVisibility(View.VISIBLE);
3809 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
3810
3811 // Show the search bar (only animate if we were showing the drop target bar in spring
3812 // loaded mode)
3813 if (mSearchDropTargetBar != null) {
3814 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
3815 }
3816
3817 // Set focus to the AppsCustomize button
3818 if (mAllAppsButton != null) {
3819 mAllAppsButton.requestFocus();
3820 }
3821 }
3822
3823 // Change the state *after* we've called all the transition code
3824 mState = State.WORKSPACE;
3825
3826 // Resume the auto-advance of widgets
3827 mUserPresent = true;
3828 updateRunning();
3829
3830 // Send an accessibility event to announce the context change
3831 getWindow().getDecorView()
3832 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3833
3834 onWorkspaceShown(animated);
3835 }
3836
3837 void showOverviewMode(boolean animated) {
3838 mWorkspace.setVisibility(View.VISIBLE);
3839 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3840 mState = State.WORKSPACE;
3841 onWorkspaceShown(animated);
3842 }
3843
3844 public void onWorkspaceShown(boolean animated) {
3845 }
3846
3847 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3848 boolean resetPageToZero) {
3849 if (mState != State.WORKSPACE) return;
3850
3851 if (resetPageToZero) {
3852 mAppsCustomizeTabHost.reset();
3853 }
3854 showAppsCustomizeHelper(animated, false, contentType);
3855 mAppsCustomizeTabHost.post(new Runnable() {
3856 @Override
3857 public void run() {
3858 // We post this in-case the all apps view isn't yet constructed.
3859 mAppsCustomizeTabHost.requestFocus();
3860 }
3861 });
3862
3863 // Change the state *after* we've called all the transition code
3864 mState = State.APPS_CUSTOMIZE;
3865
3866 // Pause the auto-advance of widgets until we are out of AllApps
3867 mUserPresent = false;
3868 updateRunning();
3869 closeFolder();
3870
3871 // Send an accessibility event to announce the context change
3872 getWindow().getDecorView()
3873 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3874 }
3875
3876 void enterSpringLoadedDragMode() {
3877 if (isAllAppsVisible()) {
3878 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
3879 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
3880 }
3881 }
3882
3883 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
3884 final Runnable onCompleteRunnable) {
3885 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3886
3887 mHandler.postDelayed(new Runnable() {
3888 @Override
3889 public void run() {
3890 if (successfulDrop) {
3891 // Before we show workspace, hide all apps again because
3892 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3893 // clean up our state transition functions
3894 mAppsCustomizeTabHost.setVisibility(View.GONE);
3895 showWorkspace(true, onCompleteRunnable);
3896 } else {
3897 exitSpringLoadedDragMode();
3898 }
3899 }
3900 }, delay);
3901 }
3902
3903 void exitSpringLoadedDragMode() {
3904 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
3905 final boolean animated = true;
3906 final boolean springLoaded = true;
3907 showAppsCustomizeHelper(animated, springLoaded);
3908 mState = State.APPS_CUSTOMIZE;
3909 }
3910 // Otherwise, we are not in spring loaded mode, so don't do anything.
3911 }
3912
3913 void lockAllApps() {
3914 // TODO
3915 }
3916
3917 void unlockAllApps() {
3918 // TODO
3919 }
3920
3921 /**
3922 * Hides the hotseat area.
3923 */
3924 void hideHotseat(boolean animated) {
3925 if (!LauncherAppState.getInstance().isScreenLarge()) {
3926 if (animated) {
3927 if (mHotseat.getAlpha() != 0f) {
3928 int duration = 0;
3929 if (mSearchDropTargetBar != null) {
3930 duration = mSearchDropTargetBar.getTransitionOutDuration();
3931 }
3932 mHotseat.animate().alpha(0f).setDuration(duration);
3933 }
3934 } else {
3935 mHotseat.setAlpha(0f);
3936 }
3937 }
3938 }
3939
3940 /**
3941 * Add an item from all apps or customize onto the given workspace screen.
3942 * If layout is null, add to the current screen.
3943 */
3944 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
3945 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
3946 showOutOfSpaceMessage(isHotseatLayout(layout));
3947 }
3948 }
3949
3950 /** Maps the current orientation to an index for referencing orientation correct global icons */
3951 private int getCurrentOrientationIndexForGlobalIcons() {
3952 // default - 0, landscape - 1
3953 switch (getResources().getConfiguration().orientation) {
3954 case Configuration.ORIENTATION_LANDSCAPE:
3955 return 1;
3956 default:
3957 return 0;
3958 }
3959 }
3960
3961 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
3962 try {
3963 PackageManager packageManager = getPackageManager();
3964 // Look for the toolbar icon specified in the activity meta-data
3965 Bundle metaData = packageManager.getActivityInfo(
3966 activityName, PackageManager.GET_META_DATA).metaData;
3967 if (metaData != null) {
3968 int iconResId = metaData.getInt(resourceName);
3969 if (iconResId != 0) {
3970 Resources res = packageManager.getResourcesForActivity(activityName);
3971 return res.getDrawable(iconResId);
3972 }
3973 }
3974 } catch (NameNotFoundException e) {
3975 // This can happen if the activity defines an invalid drawable
3976 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
3977 " not found", e);
3978 } catch (Resources.NotFoundException nfe) {
3979 // This can happen if the activity defines an invalid drawable
3980 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
3981 nfe);
3982 }
3983 return null;
3984 }
3985
3986 // if successful in getting icon, return it; otherwise, set button to use default drawable
3987 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
3988 int buttonId, ComponentName activityName, int fallbackDrawableId,
3989 String toolbarResourceName) {
3990 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
3991 Resources r = getResources();
3992 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
3993 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
3994
3995 TextView button = (TextView) findViewById(buttonId);
3996 // If we were unable to find the icon via the meta-data, use a generic one
3997 if (toolbarIcon == null) {
3998 toolbarIcon = r.getDrawable(fallbackDrawableId);
3999 toolbarIcon.setBounds(0, 0, w, h);
4000 if (button != null) {
4001 button.setCompoundDrawables(toolbarIcon, null, null, null);
4002 }
4003 return null;
4004 } else {
4005 toolbarIcon.setBounds(0, 0, w, h);
4006 if (button != null) {
4007 button.setCompoundDrawables(toolbarIcon, null, null, null);
4008 }
4009 return toolbarIcon.getConstantState();
4010 }
4011 }
4012
4013 // if successful in getting icon, return it; otherwise, set button to use default drawable
4014 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
4015 int buttonId, ComponentName activityName, int fallbackDrawableId,
4016 String toolbarResourceName) {
4017 ImageView button = (ImageView) findViewById(buttonId);
4018 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
4019
4020 if (button != null) {
4021 // If we were unable to find the icon via the meta-data, use a
4022 // generic one
4023 if (toolbarIcon == null) {
4024 button.setImageResource(fallbackDrawableId);
4025 } else {
4026 button.setImageDrawable(toolbarIcon);
4027 }
4028 }
4029
4030 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
4031
4032 }
4033
4034 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
4035 TextView button = (TextView) findViewById(buttonId);
4036 button.setCompoundDrawables(d, null, null, null);
4037 }
4038
4039 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
4040 ImageView button = (ImageView) findViewById(buttonId);
4041 button.setImageDrawable(d.newDrawable(getResources()));
4042 }
4043
4044 private void invalidatePressedFocusedStates(View container, View button) {
4045 if (container instanceof HolographicLinearLayout) {
4046 HolographicLinearLayout layout = (HolographicLinearLayout) container;
4047 layout.invalidatePressedFocusedStates();
4048 } else if (button instanceof HolographicImageView) {
4049 HolographicImageView view = (HolographicImageView) button;
4050 view.invalidatePressedFocusedStates();
4051 }
4052 }
4053
4054 public View getQsbBar() {
4055 if (mQsb == null) {
4056 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
4057 mSearchDropTargetBar.addView(mQsb);
4058 }
4059 return mQsb;
4060 }
4061
4062 protected boolean updateGlobalSearchIcon() {
4063 final View searchButtonContainer = findViewById(R.id.search_button_container);
4064 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
4065 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4066 final View voiceButton = findViewById(R.id.voice_button);
4067
4068 final SearchManager searchManager =
4069 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4070 ComponentName activityName = searchManager.getGlobalSearchActivity();
4071 if (activityName != null) {
4072 int coi = getCurrentOrientationIndexForGlobalIcons();
4073 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4074 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4075 TOOLBAR_SEARCH_ICON_METADATA_NAME);
4076 if (sGlobalSearchIcon[coi] == null) {
4077 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4078 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4079 TOOLBAR_ICON_METADATA_NAME);
4080 }
4081
4082 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
4083 searchButton.setVisibility(View.VISIBLE);
4084 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4085 return true;
4086 } else {
4087 // We disable both search and voice search when there is no global search provider
4088 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
4089 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4090 if (searchButton != null) searchButton.setVisibility(View.GONE);
4091 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4092 updateVoiceButtonProxyVisible(false);
4093 return false;
4094 }
4095 }
4096
4097 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
4098 final View searchButtonContainer = findViewById(R.id.search_button_container);
4099 final View searchButton = (ImageView) findViewById(R.id.search_button);
4100 updateButtonWithDrawable(R.id.search_button, d);
4101 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4102 }
4103
4104 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
4105 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4106 final View voiceButton = findViewById(R.id.voice_button);
4107
4108 // We only show/update the voice search icon if the search icon is enabled as well
4109 final SearchManager searchManager =
4110 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4111 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
4112
4113 ComponentName activityName = null;
4114 if (globalSearchActivity != null) {
4115 // Check if the global search activity handles voice search
4116 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4117 intent.setPackage(globalSearchActivity.getPackageName());
4118 activityName = intent.resolveActivity(getPackageManager());
4119 }
4120
4121 if (activityName == null) {
4122 // Fallback: check if an activity other than the global search activity
4123 // resolves this
4124 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4125 activityName = intent.resolveActivity(getPackageManager());
4126 }
4127 if (searchVisible && activityName != null) {
4128 int coi = getCurrentOrientationIndexForGlobalIcons();
4129 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4130 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4131 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
4132 if (sVoiceSearchIcon[coi] == null) {
4133 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4134 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4135 TOOLBAR_ICON_METADATA_NAME);
4136 }
4137 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
4138 voiceButton.setVisibility(View.VISIBLE);
4139 updateVoiceButtonProxyVisible(false);
4140 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4141 return true;
4142 } else {
4143 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4144 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4145 updateVoiceButtonProxyVisible(false);
4146 return false;
4147 }
4148 }
4149
4150 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
4151 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4152 final View voiceButton = findViewById(R.id.voice_button);
4153 updateButtonWithDrawable(R.id.voice_button, d);
4154 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4155 }
4156
4157 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
4158 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4159 if (voiceButtonProxy != null) {
4160 boolean visible = !forceDisableVoiceButtonProxy &&
4161 mWorkspace.shouldVoiceButtonProxyBeVisible();
4162 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
4163 voiceButtonProxy.bringToFront();
4164 }
4165 }
4166
4167 /**
4168 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button🔵
4169 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4170 */
4171 public void disableVoiceButtonProxy(boolean disabled) {
4172 updateVoiceButtonProxyVisible(disabled);
4173 }
4174
4175 @Override
4176 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
4177 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
4178 final List<CharSequence> text = event.getText();
4179 text.clear();
4180 // Populate event with a fake title based on the current state.
4181 if (mState == State.APPS_CUSTOMIZE) {
4182 text.add(mAppsCustomizeTabHost.getContentTag());
4183 } else {
4184 text.add(getString(R.string.all_apps_home_button_label));
4185 }
4186 return result;
4187 }
4188
4189 /**
4190 * Receives notifications when system dialogs are to be closed.
4191 */
4192 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4193 @Override
4194 public void onReceive(Context context, Intent intent) {
4195 closeSystemDialogs();
4196 }
4197 }
4198
4199 /**
4200 * Receives notifications whenever the appwidgets are reset.
4201 */
4202 private class AppWidgetResetObserver extends ContentObserver {
4203 public AppWidgetResetObserver() {
4204 super(new Handler());
4205 }
4206
4207 @Override
4208 public void onChange(boolean selfChange) {
4209 onAppWidgetReset();
4210 }
4211 }
4212
4213 /**
4214 * If the activity is currently paused, signal that we need to run the passed Runnable
4215 * in onResume.
4216 *
4217 * This needs to be called from incoming places where resources might have been loaded
4218 * while we are paused. That is becaues the Configuration might be wrong
4219 * when we're not running, and if it comes back to what it was when we
4220 * were paused, we are not restarted.
4221 *
4222 * Implementation of the method from LauncherModel.Callbacks.
4223 *
4224 * @return true if we are currently paused. The caller might be able to
4225 * skip some work in that case since we will come back again.
4226 */
4227 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
4228 if (mPaused) {
4229 Log.i(TAG, "Deferring update until onResume");
4230 if (deletePreviousRunnables) {
4231 while (mBindOnResumeCallbacks.remove(run)) {
4232 }
4233 }
4234 mBindOnResumeCallbacks.add(run);
4235 return true;
4236 } else {
4237 return false;
4238 }
4239 }
4240
4241 private boolean waitUntilResume(Runnable run) {
4242 return waitUntilResume(run, false);
4243 }
4244
4245 public void addOnResumeCallback(Runnable run) {
4246 mOnResumeCallbacks.add(run);
4247 }
4248
4249 /**
4250 * If the activity is currently paused, signal that we need to re-run the loader
4251 * in onResume.
4252 *
4253 * This needs to be called from incoming places where resources might have been loaded
4254 * while we are paused. That is becaues the Configuration might be wrong
4255 * when we're not running, and if it comes back to what it was when we
4256 * were paused, we are not restarted.
4257 *
4258 * Implementation of the method from LauncherModel.Callbacks.
4259 *
4260 * @return true if we are currently paused. The caller might be able to
4261 * skip some work in that case since we will come back again.
4262 */
4263 public boolean setLoadOnResume() {
4264 if (mPaused) {
4265 Log.i(TAG, "setLoadOnResume");
4266 mOnResumeNeedsLoad = true;
4267 return true;
4268 } else {
4269 return false;
4270 }
4271 }
4272
4273 /**
4274 * Implementation of the method from LauncherModel.Callbacks.
4275 */
4276 public int getCurrentWorkspaceScreen() {
4277 if (mWorkspace != null) {
4278 return mWorkspace.getCurrentPage();
4279 } else {
4280 return SCREEN_COUNT / 2;
4281 }
4282 }
4283
4284 /**
4285 * Refreshes the shortcuts shown on the workspace.
4286 *
4287 * Implementation of the method from LauncherModel.Callbacks.
4288 */
4289 public void startBinding() {
4290 setWorkspaceLoading(true);
4291
4292 // If we're starting binding all over again, clear any bind calls we'd postponed in
4293 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4294 // from scratch again
4295 mBindOnResumeCallbacks.clear();
4296
4297 // Clear the workspace because it's going to be rebound
4298 mWorkspace.clearDropTargets();
4299 mWorkspace.removeAllWorkspaceScreens();
4300
4301 mWidgetsToAdvance.clear();
4302 if (mHotseat != null) {
4303 mHotseat.resetLayout();
4304 }
4305 }
4306
4307 @Override
4308 public void bindScreens(ArrayList<Long> orderedScreenIds) {
4309 bindAddScreens(orderedScreenIds);
4310
4311 // If there are no screens, we need to have an empty screen
4312 if (orderedScreenIds.size() == 0) {
4313 mWorkspace.addExtraEmptyScreen();
4314 }
4315
4316 // Create the custom content page (this call updates mDefaultScreen which calls
4317 // setCurrentPage() so ensure that all pages are added before calling this).
4318 if (hasCustomContentToLeft()) {
4319 mWorkspace.createCustomContentContainer();
4320 populateCustomContentContainer();
4321 }
4322 }
4323
4324 @Override
4325 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
4326 // Log to disk
4327 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4328 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4329 TextUtils.join(", ", orderedScreenIds), true);
4330 int count = orderedScreenIds.size();
4331 for (int i = 0; i < count; i++) {
4332 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
4333 }
4334 }
4335
4336 private boolean shouldShowWeightWatcher() {
4337 String spKey = LauncherAppState.getSharedPreferencesKey();
4338 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4339 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
4340
4341 return show;
4342 }
4343
4344 private void toggleShowWeightWatcher() {
4345 String spKey = LauncherAppState.getSharedPreferencesKey();
4346 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4347 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4348
4349 show = !show;
4350
4351 SharedPreferences.Editor editor = sp.edit();
4352 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4353 editor.commit();
4354
4355 if (mWeightWatcher != null) {
4356 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4357 }
4358 }
4359
4360 public void bindAppsAdded(final ArrayList<Long> newScreens,
4361 final ArrayList<ItemInfo> addNotAnimated,
4362 final ArrayList<ItemInfo> addAnimated,
4363 final ArrayList<AppInfo> addedApps) {
4364 Runnable r = new Runnable() {
4365 public void run() {
4366 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
4367 }
4368 };
4369 if (waitUntilResume(r)) {
4370 return;
4371 }
4372
4373 // Add the new screens
4374 if (newScreens != null) {
4375 bindAddScreens(newScreens);
4376 }
4377
4378 // We add the items without animation on non-visible pages, and with
4379 // animations on the new page (which we will try and snap to).
4380 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
4381 bindItems(addNotAnimated, 0,
4382 addNotAnimated.size(), false);
4383 }
4384 if (addAnimated != null && !addAnimated.isEmpty()) {
4385 bindItems(addAnimated, 0,
4386 addAnimated.size(), true);
4387 }
4388
4389 // Remove the extra empty screen
4390 mWorkspace.removeExtraEmptyScreen(false, false);
4391
4392 if (!LauncherAppState.isDisableAllApps() &&
4393 addedApps != null && mAppsCustomizeContent != null) {
4394 mAppsCustomizeContent.addApps(addedApps);
4395 }
4396 }
4397
4398 /**
4399 * Bind the items start-end from the list.
4400 *
4401 * Implementation of the method from LauncherModel.Callbacks.
4402 */
4403 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4404 final boolean forceAnimateIcons) {
4405 Runnable r = new Runnable() {
4406 public void run() {
4407 bindItems(shortcuts, start, end, forceAnimateIcons);
4408 }
4409 };
4410 if (waitUntilResume(r)) {
4411 return;
4412 }
4413
4414 // Get the list of added shortcuts and intersect them with the set of shortcuts here
4415 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4416 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
4417 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
4418 Workspace workspace = mWorkspace;
4419 long newShortcutsScreenId = -1;
4420 for (int i = start; i < end; i++) {
4421 final ItemInfo item = shortcuts.get(i);
4422
4423 // Short circuit if we are loading dock items for a configuration which has no dock
4424 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4425 mHotseat == null) {
4426 continue;
4427 }
4428
4429 switch (item.itemType) {
4430 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4431 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
4432 ShortcutInfo info = (ShortcutInfo) item;
4433 View shortcut = createShortcut(info);
4434
4435 /*
4436 * TODO: FIX collision case
4437 */
4438 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4439 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4440 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
4441 View v = cl.getChildAt(item.cellX, item.cellY);
4442 Object tag = v.getTag();
4443 String desc = "Collision while binding workspace item: " + item
4444 + ". Collides with " + tag;
4445 if (LauncherAppState.isDogfoodBuild()) {
4446 throw (new RuntimeException(desc));
4447 } else {
4448 Log.d(TAG, desc);
4449 }
4450 }
4451 }
4452
4453 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4454 item.cellY, 1, 1);
4455 if (animateIcons) {
4456 // Animate all the applications up now
4457 shortcut.setAlpha(0f);
4458 shortcut.setScaleX(0f);
4459 shortcut.setScaleY(0f);
4460 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
4461 newShortcutsScreenId = item.screenId;
4462 }
4463 break;
4464 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
4465 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
4466 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
4467 (FolderInfo) item, mIconCache);
4468 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4469 item.cellY, 1, 1);
4470 break;
4471 default:
4472 throw new RuntimeException("Invalid Item Type");
4473 }
4474 }
4475
4476 if (animateIcons) {
4477 // Animate to the correct page
4478 if (newShortcutsScreenId > -1) {
4479 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
4480 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
4481 final Runnable startBounceAnimRunnable = new Runnable() {
4482 public void run() {
4483 anim.playTogether(bounceAnims);
4484 anim.start();
4485 }
4486 };
4487 if (newShortcutsScreenId != currentScreenId) {
4488 // We post the animation slightly delayed to prevent slowdowns
4489 // when we are loading right after we return to launcher.
4490 mWorkspace.postDelayed(new Runnable() {
4491 public void run() {
4492 if (mWorkspace != null) {
4493 mWorkspace.snapToPage(newScreenIndex);
4494 mWorkspace.postDelayed(startBounceAnimRunnable,
4495 NEW_APPS_ANIMATION_DELAY);
4496 }
4497 }
4498 }, NEW_APPS_PAGE_MOVE_DELAY);
4499 } else {
4500 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
4501 }
4502 }
4503 }
4504 workspace.requestLayout();
4505 }
4506
4507 /**
4508 * Implementation of the method from LauncherModel.Callbacks.
4509 */
4510 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
4511 Runnable r = new Runnable() {
4512 public void run() {
4513 bindFolders(folders);
4514 }
4515 };
4516 if (waitUntilResume(r)) {
4517 return;
4518 }
4519 sFolders.clear();
4520 sFolders.putAll(folders);
4521 }
4522
4523 /**
4524 * Add the views for a widget to the workspace.
4525 *
4526 * Implementation of the method from LauncherModel.Callbacks.
4527 */
4528 public void bindAppWidget(final LauncherAppWidgetInfo item) {
4529 Runnable r = new Runnable() {
4530 public void run() {
4531 bindAppWidget(item);
4532 }
4533 };
4534 if (waitUntilResume(r)) {
4535 return;
4536 }
4537
4538 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4539 if (DEBUG_WIDGETS) {
4540 Log.d(TAG, "bindAppWidget: " + item);
4541 }
4542 final Workspace workspace = mWorkspace;
4543
4544 AppWidgetProviderInfo appWidgetInfo;
4545 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4546 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4547
4548 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4549 if (appWidgetInfo == null) {
4550 if (DEBUG_WIDGETS) {
4551 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4552 + " belongs to component " + item.providerName
4553 + ", as the povider is null");
4554 }
4555 LauncherModel.deleteItemFromDatabase(this, item);
4556 return;
4557 }
4558 // Note: This assumes that the id remap broadcast is received before this step.
4559 // If that is not the case, the id remap will be ignored and user may see the
4560 // click to setup view.
4561 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4562 pendingInfo.spanX = item.spanX;
4563 pendingInfo.spanY = item.spanY;
4564 pendingInfo.minSpanX = item.minSpanX;
4565 pendingInfo.minSpanY = item.minSpanY;
4566 Bundle options =
4567 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4568
4569 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4570 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4571 newWidgetId, appWidgetInfo, options);
4572
4573 // TODO consider showing a permission dialog when the widget is clicked.
4574 if (!success) {
4575 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4576 if (DEBUG_WIDGETS) {
4577 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4578 + " belongs to component " + item.providerName
4579 + ", as the launcher is unable to bing a new widget id");
4580 }
4581 LauncherModel.deleteItemFromDatabase(this, item);
4582 return;
4583 }
4584
4585 item.appWidgetId = newWidgetId;
4586
4587 // If the widget has a configure activity, it is still needs to set it up, otherwise
4588 // the widget is ready to go.
4589 item.restoreStatus = (appWidgetInfo.configure == null)
4590 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4591 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4592
4593 LauncherModel.updateItemInDatabase(this, item);
4594 }
4595
4596 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4597 final int appWidgetId = item.appWidgetId;
4598 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4599 if (DEBUG_WIDGETS) {
4600 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo🔵
4601 }
4602
4603 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4604 } else {
4605 appWidgetInfo = null;
4606 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4607 view.updateIcon(mIconCache);
4608 item.hostView = view;
4609 item.hostView.updateAppWidget(null);
4610 item.hostView.setOnClickListener(this);
4611 }
4612
4613 item.hostView.setTag(item);
4614 item.onBindAppWidget(this);
4615
4616 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
4617 item.cellY, item.spanX, item.spanY, false);
4618 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4619
4620 workspace.requestLayout();
4621
4622 if (DEBUG_WIDGETS) {
4623 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4624 + (SystemClock.uptimeMillis()-start) + "ms");
4625 }
4626 }
4627
4628 /**
4629 * Restores a pending widget.
4630 *
4631 * @param appWidgetId The app widget id
4632 * @param cellInfo The position on screen where to create the widget.
4633 */
4634 private void completeRestoreAppWidget(final int appWidgetId) {
4635 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4636 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4637 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4638 return;
4639 }
4640
4641 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
4642 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4643
4644 mWorkspace.reinflateWidgetsIfNecessary();
4645 LauncherModel.updateItemInDatabase(this, info);
4646 }
4647
4648 public void onPageBoundSynchronously(int page) {
4649 mSynchronouslyBoundPages.add(page);
4650 }
4651
4652 /**
4653 * Callback saying that there aren't any more items to bind.
4654 *
4655 * Implementation of the method from LauncherModel.Callbacks.
4656 */
4657 public void finishBindingItems(final boolean upgradePath) {
4658 Runnable r = new Runnable() {
4659 public void run() {
4660 finishBindingItems(upgradePath);
4661 }
4662 };
4663 if (waitUntilResume(r)) {
4664 return;
4665 }
4666 if (mSavedState != null) {
4667 if (!mWorkspace.hasFocus()) {
4668 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
4669 }
4670 mSavedState = null;
4671 }
4672
4673 mWorkspace.restoreInstanceStateForRemainingPages();
4674
4675 setWorkspaceLoading(false);
4676 sendLoadingCompleteBroadcastIfNecessary();
4677
4678 // If we received the result of any pending adds while the loader was running (e.g. the
4679 // widget configuration forced an orientation change), process them now.
4680 if (sPendingAddItem != null) {
4681 final long screenId = completeAdd(sPendingAddItem);
4682
4683 // TODO: this moves the user to the page where the pending item was added. Ideally,
4684 // the screen would be guaranteed to exist after bind, and the page would be set through
4685 // the workspace restore process.
4686 mWorkspace.post(new Runnable() {
4687 @Override
4688 public void run() {
4689 mWorkspace.snapToScreenId(screenId);
4690 }
4691 });
4692 sPendingAddItem = null;
4693 }
4694
4695 if (upgradePath) {
4696 mWorkspace.getUniqueComponents(true, null);
4697 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
4698 }
4699 PackageInstallerCompat.getInstance(this).onFinishBind();
4700 mModel.recheckRestoredItems(this);
4701 }
4702
4703 private void sendLoadingCompleteBroadcastIfNecessary() {
4704 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4705 String permission =
4706 getResources().getString(R.string.receive_first_load_broadcast_permission);
4707 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4708 sendBroadcast(intent, permission);
4709 SharedPreferences.Editor editor = mSharedPrefs.edit();
4710 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4711 editor.apply();
4712 }
4713 }
4714
4715 public boolean isAllAppsButtonRank(int rank) {
4716 if (mHotseat != null) {
4717 return mHotseat.isAllAppsButtonRank(rank);
4718 }
4719 return false;
4720 }
4721
4722 private boolean canRunNewAppsAnimation() {
4723 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4724 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4725 }
4726
4727 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4728 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4729 PropertyValuesHolder.ofFloat("alpha", 1f),
4730 PropertyValuesHolder.ofFloat("scaleX", 1f),
4731 PropertyValuesHolder.ofFloat("scaleY", 1f));
4732 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4733 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4734 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4735 return bounceAnim;
4736 }
4737
4738 public boolean useVerticalBarLayout() {
4739 return LauncherAppState.getInstance().getDynamicGrid().
4740 getDeviceProfile().isVerticalBarLayout();
4741 }
4742
4743 protected Rect getSearchBarBounds() {
4744 return LauncherAppState.getInstance().getDynamicGrid().
4745 getDeviceProfile().getSearchBarBounds();
4746 }
4747
4748 @Override
4749 public void bindSearchablesChanged() {
4750 boolean searchVisible = updateGlobalSearchIcon();
4751 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
4752 if (mSearchDropTargetBar != null) {
4753 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4754 }
4755 }
4756
4757 /**
4758 * Add the icons for all apps.
4759 *
4760 * Implementation of the method from LauncherModel.Callbacks.
4761 */
4762 public void bindAllApplications(final ArrayList<AppInfo> apps) {
4763 if (LauncherAppState.isDisableAllApps()) {
4764 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4765 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4766 getHotseat().addAllAppsFolder(mIconCache, apps,
4767 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4768 }
4769 mIntentsOnWorkspaceFromUpgradePath = null;
4770 }
4771 if (mAppsCustomizeContent != null) {
4772 mAppsCustomizeContent.onPackagesUpdated(
4773 LauncherModel.getSortedWidgetsAndShortcuts(this));
4774 }
4775 } else {
4776 if (mAppsCustomizeContent != null) {
4777 mAppsCustomizeContent.setApps(apps);
4778 mAppsCustomizeContent.onPackagesUpdated(
4779 LauncherModel.getSortedWidgetsAndShortcuts(this));
4780 }
4781 }
4782 }
4783
4784 /**
4785 * A package was updated.
4786 *
4787 * Implementation of the method from LauncherModel.Callbacks.
4788 */
4789 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
4790 Runnable r = new Runnable() {
4791 public void run() {
4792 bindAppsUpdated(apps);
4793 }
4794 };
4795 if (waitUntilResume(r)) {
4796 return;
4797 }
4798
4799 if (mWorkspace != null) {
4800 mWorkspace.updateShortcutsAndWidgets(apps);
4801 }
4802
4803 if (!LauncherAppState.isDisableAllApps() &&
4804 mAppsCustomizeContent != null) {
4805 mAppsCustomizeContent.updateApps(apps);
4806 }
4807 }
4808
4809 /**
4810 * Packages were restored
4811 */
4812 public void bindAppsRestored(final ArrayList<AppInfo> apps) {
4813 Runnable r = new Runnable() {
4814 public void run() {
4815 bindAppsRestored(apps);
4816 }
4817 };
4818 if (waitUntilResume(r)) {
4819 return;
4820 }
4821
4822 if (mWorkspace != null) {
4823 mWorkspace.updateShortcutsAndWidgets(apps);
4824 }
4825 }
4826
4827 /**
4828 * Update the state of a package, typically related to install state.
4829 *
4830 * Implementation of the method from LauncherModel.Callbacks.
4831 */
4832 @Override
4833 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
4834 if (mWorkspace != null) {
4835 mWorkspace.updatePackageState(installInfo);
4836 }
4837 }
4838
4839 /**
4840 * Update the label and icon of all the icons in a package
4841 *
4842 * Implementation of the method from LauncherModel.Callbacks.
4843 */
4844 @Override
4845 public void updatePackageBadge(String packageName) {
4846 if (mWorkspace != null) {
4847 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4848 }
4849 }
4850
4851 /**
4852 * A package was uninstalled. We take both the super set of packageNames
4853 * in addition to specific applications to remove, the reason being that
4854 * this can be called when a package is updated as well. In that scenario,
4855 * we only remove specific components from the workspace, where as
4856 * package-removal should clear all items by package name.
4857 *
4858 * Implementation of the method from LauncherModel.Callbacks.
4859 */
4860 public void bindComponentsRemoved(final ArrayList<String> packageNames,
4861 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
4862 Runnable r = new Runnable() {
4863 public void run() {
4864 bindComponentsRemoved(packageNames, appInfos, user);
4865 }
4866 };
4867 if (waitUntilResume(r)) {
4868 return;
4869 }
4870
4871 if (!packageNames.isEmpty()) {
4872 mWorkspace.removeItemsByPackageName(packageNames, user);
4873 }
4874 if (!appInfos.isEmpty()) {
4875 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
4876 }
4877
4878 // Notify the drag controller
4879 mDragController.onAppsRemoved(packageNames, appInfos);
4880
4881 // Update AllApps
4882 if (!LauncherAppState.isDisableAllApps() &&
4883 mAppsCustomizeContent != null) {
4884 mAppsCustomizeContent.removeApps(appInfos);
4885 }
4886 }
4887
4888 /**
4889 * A number of packages were updated.
4890 */
4891 private ArrayList<Object> mWidgetsAndShortcuts;
4892 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
4893 public void run() {
4894 bindPackagesUpdated(mWidgetsAndShortcuts);
4895 mWidgetsAndShortcuts = null;
4896 }
4897 };
4898 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4899 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4900 mWidgetsAndShortcuts = widgetsAndShortcuts;
4901 return;
4902 }
4903
4904 // Update the widgets pane
4905 if (mAppsCustomizeContent != null) {
4906 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
4907 }
4908 }
4909
4910 private int mapConfigurationOriActivityInfoOri(int configOri) {
4911 final Display d = getWindowManager().getDefaultDisplay();
4912 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4913 switch (d.getRotation()) {
4914 case Surface.ROTATION_0:
4915 case Surface.ROTATION_180:
4916 // We are currently in the same basic orientation as the natural orientation
4917 naturalOri = configOri;
4918 break;
4919 case Surface.ROTATION_90:
4920 case Surface.ROTATION_270:
4921 // We are currently in the other basic orientation to the natural orientation
4922 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4923 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4924 break;
4925 }
4926
4927 int[] oriMap = {
4928 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4929 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4930 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4931 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4932 };
4933 // Since the map starts at portrait, we need to offset if this device's natural orientation
4934 // is landscape.
4935 int indexOffset = 0;
4936 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4937 indexOffset = 1;
4938 }
4939 return oriMap[(d.getRotation() + indexOffset) % 4];
4940 }
4941
4942 public boolean isRotationEnabled() {
4943 boolean enableRotation = sForceEnableRotation ||
4944 getResources().getBoolean(R.bool.allow_rotation);
4945 return enableRotation;
4946 }
4947 public void lockScreenOrientation() {
4948 if (isRotationEnabled()) {
4949 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4950 .getConfiguration().orientation));
4951 }
4952 }
4953 public void unlockScreenOrientation(boolean immediate) {
4954 if (isRotationEnabled()) {
4955 if (immediate) {
4956 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4957 } else {
4958 mHandler.postDelayed(new Runnable() {
4959 public void run() {
4960 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4961 }
4962 }, mRestoreScreenOrientationDelay);
4963 }
4964 }
4965 }
4966
4967 /**
4968 * Called when the SearchBar hint should be changed.
4969 *
4970 * @param hint the hint to be displayed in the search bar.
4971 */
4972 protected void onSearchBarHintChanged(String hint) {
4973 <<<<<<< MINE
4974
4975 ||||||| BASE
4976 Cling cling = (Cling) findViewById(R.id.first_run_cling);
4977 =======
4978 mLauncherClings.updateSearchBarHint(hint);
4979 >>>>>>> YOURS
4980 }
4981
4982 protected boolean isLauncherPreinstalled() {
4983 PackageManager pm = getPackageManager();
4984 try {
4985 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
4986 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
4987 return true;
4988 } else {
4989 return false;
4990 }
4991 } catch (NameNotFoundException e) {
4992 e.printStackTrace();
4993 return false;
4994 }
4995 }
4996
4997 /**
4998 * This method indicates whether or not we should suggest default wallpaper dimensions
4999 * when our wallpaper cropper was not yet used to set a wallpaper.
5000 */
5001 protected boolean overrideWallpaperDimensions() {
5002 return true;
5003 }
5004
5005 protected boolean shouldClingFocusHotseatApp() {
5006 return false;
5007 }
5008 protected String getFirstRunClingSearchBarHint() {
5009 return "";
5010 }
5011 protected String getFirstRunCustomContentHint() {
5012 return "";
5013 }
5014 protected int getFirstRunFocusedHotseatAppDrawableId() {
5015 return -1;
5016 }
5017 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
5018 return null;
5019 }
5020 protected int getFirstRunFocusedHotseatAppRank() {
5021 return -1;
5022 }
5023 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
5024 return "";
5025 }
5026 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
5027 return "";
5028 }
5029 <<<<<<< MINE
5030 ||||||| BASE
5031 public void dismissFirstRunCling(View v) {
5032 Cling cling = (Cling) findViewById(R.id.first_run_cling);
5033 Runnable cb = new Runnable() {
5034 public void run() {
5035 // Show the workspace cling next
5036 showFirstRunWorkspaceCling();
5037 }
5038 };
5039 dismissCling(cling, cb, Cling.FIRST_RUN_CLING_DISMISSED_KEY,
5040 DISMISS_CLING_DURATION, false);
5041
5042 // Fade out the search bar for the workspace cling coming up
5043 mSearchDropTargetBar.hideSearchBar(true);
5044 }
5045 =======
5046 public void dismissFirstRunCling(View v) {
5047 mLauncherClings.dismissFirstRunCling(v);
5048 }
5049 >>>>>>> YOURS
5050
5051 public void dismissMigrationClingCopyApps(View v) {
5052 mLauncherClings.dismissMigrationClingCopyApps(v);
5053 }
5054 public void dismissMigrationClingUseDefault(View v) {
5055 mLauncherClings.dismissMigrationClingUseDefault(v);
5056 }
5057 public void dismissMigrationWorkspaceCling(View v) {
5058 mLauncherClings.dismissMigrationWorkspaceCling(v);
5059 }
5060 <<<<<<< MINE
5061 ||||||| BASE
5062 public void dismissWorkspaceCling(View v) {
5063 Cling cling = (Cling) findViewById(R.id.workspace_cling);
5064 Runnable cb = null;
5065 if (v == null) {
5066 cb = new Runnable() {
5067 public void run() {
5068 mWorkspace.enterOverviewMode();
5069 }
5070 };
5071 }
5072 dismissCling(cling, cb, Cling.WORKSPACE_CLING_DISMISSED_KEY,
5073 DISMISS_CLING_DURATION, true);
5074
5075 // Fade in the search bar
5076 mSearchDropTargetBar.showSearchBar(true);
5077 }
5078 =======
5079 public void dismissWorkspaceCling(View v) {
5080 mLauncherClings.dismissWorkspaceCling(v);
5081 }
5082 >>>>>>> YOURS
5083 <<<<<<< MINE
5084 ||||||| BASE
5085 public void dismissFolderCling(View v) {
5086 Cling cling = (Cling) findViewById(R.id.folder_cling);
5087 dismissCling(cling, null, Cling.FOLDER_CLING_DISMISSED_KEY,
5088 DISMISS_CLING_DURATION, true);
5089 }
5090 =======
5091 public void dismissFolderCling(View v) {
5092 mLauncherClings.dismissFolderCling(v);
5093 }
5094 >>>>>>> YOURS
5095
5096
5097 private boolean shouldRunFirstRunActivity() {
5098 return !ActivityManager.isRunningInTestHarness() &&
5099 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5100 }
5101
5102 protected boolean hasRunFirstRunActivity() {
5103 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5104 }
5105
5106 public boolean showFirstRunActivity() {
5107 if (shouldRunFirstRunActivity() &&
5108 hasFirstRunActivity()) {
5109 Intent firstRunIntent = getFirstRunActivity();
5110 if (firstRunIntent != null) {
5111 startActivity(firstRunIntent);
5112 markFirstRunActivityShown();
5113 return true;
5114 }
5115 }
5116 return false;
5117 }
5118
5119 private void markFirstRunActivityShown() {
5120 SharedPreferences.Editor editor = mSharedPrefs.edit();
5121 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
5122 editor.apply();
5123 }
5124
5125 /**
5126 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
5127 * screen that must be displayed and dismissed.
5128 */
5129 protected boolean hasDismissableIntroScreen() {
5130 return false;
5131 }
5132
5133 /**
5134 * Full screen intro screen to be shown and dismissed before the launcher can be used.
5135 */
5136 protected View getIntroScreen() {
5137 return null;
5138 }
5139
5140 /**
5141 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
5142 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
5143 */
5144 private boolean shouldShowIntroScreen() {
5145 return hasDismissableIntroScreen() &&
5146 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
5147 }
5148
5149 protected void showIntroScreen() {
5150 View introScreen = getIntroScreen();
5151 changeWallpaperVisiblity(false);
5152 if (introScreen != null) {
5153 mDragLayer.showOverlayView(introScreen);
5154 }
5155 }
5156
5157 public void dismissIntroScreen() {
5158 markIntroScreenDismissed();
5159 if (showFirstRunActivity()) {
5160 // We delay hiding the intro view until the first run activity is showing. This
5161 // avoids a blip.
5162 mWorkspace.postDelayed(new Runnable() {
5163 @Override
5164 public void run() {
5165 mDragLayer.dismissOverlayView();
5166 showFirstRunClings();
5167 }
5168 }, ACTIVITY_START_DELAY);
5169 } else {
5170 mDragLayer.dismissOverlayView();
5171 showFirstRunClings();
5172 }
5173 changeWallpaperVisiblity(true);
5174 }
5175
5176 private void markIntroScreenDismissed() {
5177 SharedPreferences.Editor editor = mSharedPrefs.edit();
5178 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5179 editor.apply();
5180 }
5181
5182 private void showFirstRunClings() {
5183 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
5184 // on the device, then we always show the first run cling experience (or if there is no
5185 // launcher2). Otherwise, we prompt the user upon started for migration
5186 LauncherClings launcherClings = new LauncherClings(this);
5187 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5188 if (mModel.canMigrateFromOldLauncherDb(this)) {
5189 launcherClings.showMigrationCling();
5190 } else {
5191 launcherClings.showLongPressCling(true);
5192 }
5193 }
5194 }
5195
5196 void showWorkspaceSearchAndHotseat() {
5197 <<<<<<< MINE
5198 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5199 if (mHotseat != null) mHotseat.setAlpha(1f);
5200 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5201 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
5202 ||||||| BASE
5203 =======
5204 mWorkspace.setAlpha(1f);
5205 mHotseat.setAlpha(1f);
5206 mPageIndicators.setAlpha(1f);
5207 mSearchDropTargetBar.showSearchBar(false);
5208 >>>>>>> YOURS
5209 }
5210
5211 void hideWorkspaceSearchAndHotseat() {
5212 <<<<<<< MINE
5213 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5214 if (mHotseat != null) mHotseat.setAlpha(0f);
5215 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5216 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
5217 ||||||| BASE
5218 =======
5219 mWorkspace.setAlpha(0f);
5220 mHotseat.setAlpha(0f);
5221 mPageIndicators.setAlpha(0f);
5222 mSearchDropTargetBar.hideSearchBar(false);
5223 >>>>>>> YOURS
5224 }
5225
5226
5227 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
5228 // Called from search suggestion, not supported in other profiles.
5229 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5230 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5231 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5232 myUser);
5233 if (activityInfo == null) {
5234 return null;
5235 }
5236 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
5237 }
5238
5239 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5240 Bitmap icon) {
5241 // Called from search suggestion, not supported in other profiles.
5242 return createShortcutDragInfo(shortcutIntent, caption, icon,
5243 UserHandleCompat.myUserHandle());
5244 }
5245
5246 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5247 Bitmap icon, UserHandleCompat user) {
5248 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
5249 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
5250 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
5251 }
5252
5253 protected void moveWorkspaceToDefaultScreen() {
5254 mWorkspace.moveToDefaultScreen(false);
5255 }
5256
5257 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5258 dragView.setTag(dragInfo);
5259 mWorkspace.onExternalDragStartedWithItem(dragView);
5260 mWorkspace.beginExternalDragShared(dragView, source);
5261 }
5262
5263 @Override
5264 public void onPageSwitch(View newPage, int newPageIndex) {
5265 }
5266
5267 /**
5268 * Prints out out state for debugging.
5269 */
5270 public void dumpState() {
5271 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
5272 Log.d(TAG, "mSavedState=" + mSavedState);
5273 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5274 Log.d(TAG, "mRestoring=" + mRestoring);
5275 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5276 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
5277 Log.d(TAG, "sFolders.size=" + sFolders.size());
5278 mModel.dumpState();
5279
5280 if (mAppsCustomizeContent != null) {
5281 mAppsCustomizeContent.dumpState();
5282 }
5283 Log.d(TAG, "END launcher3 dump state");
5284 }
5285
5286 @Override
5287 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5288 super.dump(prefix, fd, writer, args);
5289 synchronized (sDumpLogs) {
5290 writer.println(" ");
5291 writer.println("Debug logs: ");
5292 for (int i = 0; i < sDumpLogs.size(); i++) {
5293 writer.println(" " + sDumpLogs.get(i));
5294 }
5295 }
5296 }
5297
5298 public static void dumpDebugLogsToConsole() {
5299 if (DEBUG_DUMP_LOG) {
5300 synchronized (sDumpLogs) {
5301 Log.d(TAG, "");
5302 Log.d(TAG, "*********************");
5303 Log.d(TAG, "Launcher debug logs: ");
5304 for (int i = 0; i < sDumpLogs.size(); i++) {
5305 Log.d(TAG, " " + sDumpLogs.get(i));
5306 }
5307 Log.d(TAG, "*********************");
5308 Log.d(TAG, "");
5309 }
5310 }
5311 }
5312
5313 public static void addDumpLog(String tag, String log, boolean debugLog) {
5314 addDumpLog(tag, log, null, debugLog);
5315 }
5316
5317 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
5318 if (debugLog) {
5319 if (e != null) {
5320 Log.d(tag, log, e);
5321 } else {
5322 Log.d(tag, log);
5323 }
5324 }
5325 if (DEBUG_DUMP_LOG) {
5326 sDateStamp.setTime(System.currentTimeMillis());
5327 synchronized (sDumpLogs) {
5328 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5329 + (e == null ? "" : (", Exception: " + e)));
5330 }
5331 }
5332 }
5333
5334 public void dumpLogsToLocalData() {
5335 if (DEBUG_DUMP_LOG) {
5336 new AsyncTask<Void, Void, Void>() {
5337 public Void doInBackground(Void ... args) {
5338 boolean success = false;
5339 sDateStamp.setTime(sRunStart);
5340 String FILENAME = sDateStamp.getMonth() + "-"
5341 + sDateStamp.getDay() + "_"
5342 + sDateStamp.getHours() + "-"
5343 + sDateStamp.getMinutes() + "_"
5344 + sDateStamp.getSeconds() + ".txt";
5345
5346 FileOutputStream fos = null;
5347 File outFile = null;
5348 try {
5349 outFile = new File(getFilesDir(), FILENAME);
5350 outFile.createNewFile();
5351 fos = new FileOutputStream(outFile);
5352 } catch (Exception e) {
5353 e.printStackTrace();
5354 }
5355 if (fos != null) {
5356 PrintWriter writer = new PrintWriter(fos);
5357
5358 writer.println(" ");
5359 writer.println("Debug logs: ");
5360 synchronized (sDumpLogs) {
5361 for (int i = 0; i < sDumpLogs.size(); i++) {
5362 writer.println(" " + sDumpLogs.get(i));
5363 }
5364 }
5365 writer.close();
5366 }
5367 try {
5368 if (fos != null) {
5369 fos.close();
5370 success = true;
5371 }
5372 } catch (IOException e) {
5373 e.printStackTrace();
5374 }
5375 return null;
5376 }
5377 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
5378 }
5379 }
5380 }
5381
5382 interface LauncherTransitionable {
5383 View getContent();
5384 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
5385 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
5386 void onLauncherTransitionStep(Launcher l, float t);
5387 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
5388 }
5389
5390 interface DebugIntents {
5391 static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
5392 static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
5393 }
|
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.android.launcher3;
17
18 import android.animation.Animator;
19 import android.animation.AnimatorListenerAdapter;
20 import android.animation.AnimatorSet;
21 import android.animation.ObjectAnimator;
22 import android.animation.PropertyValuesHolder;
23 import android.animation.TimeInterpolator;
24 import android.animation.ValueAnimator;
25 import android.annotation.TargetApi;
26 import android.app.Activity;
27 import android.app.ActivityManager;
28 import android.app.ActivityOptions;
29 import android.app.AlertDialog;
30 import android.app.SearchManager;
31 import android.appwidget.AppWidgetHostView;
32 import android.appwidget.AppWidgetManager;
33 import android.appwidget.AppWidgetProviderInfo;
34 import android.content.ActivityNotFoundException;
35 import android.content.BroadcastReceiver;
36 import android.content.ComponentCallbacks2;
37 import android.content.ComponentName;
38 import android.content.ContentResolver;
39 import android.content.Context;
40 import android.content.DialogInterface;
41 import android.content.Intent;
42 import android.content.IntentFilter;
43 import android.content.SharedPreferences;
44 import android.content.pm.ActivityInfo;
45 import android.content.pm.ApplicationInfo;
46 import android.content.pm.PackageManager.NameNotFoundException;
47 import android.content.pm.PackageManager;
48 import android.content.res.Configuration;
49 import android.content.res.Resources;
50 import android.database.ContentObserver;
51 import android.graphics.Bitmap;
52 import android.graphics.Canvas;
53 import android.graphics.Color;
54 import android.graphics.Point;
55 import android.graphics.PorterDuff;
56 import android.graphics.Rect;
57 import android.graphics.drawable.Drawable;
58 import android.net.Uri;
59 import android.os.AsyncTask;
60 import android.os.Build;
61 import android.os.Bundle;
62 import android.os.Environment;
63 import android.os.Handler;
64 import android.os.Message;
65 import android.os.StrictMode;
66 import android.os.SystemClock;
67 import android.speech.RecognizerIntent;
68 import android.text.Selection;
69 import android.text.SpannableStringBuilder;
70 import android.text.TextUtils;
71 import android.text.method.TextKeyListener;
72 import android.util.DisplayMetrics;
73 import android.util.Log;
74 import android.view.ContextThemeWrapper;
75 import android.view.Display;
76 import android.view.Gravity;
77 import android.view.HapticFeedbackConstants;
78 import android.view.KeyEvent;
79 import android.view.LayoutInflater;
80 import android.view.Menu;
81 import android.view.MotionEvent;
82 import android.view.Surface;
83 import android.view.View.OnClickListener;
84 import android.view.View.OnLongClickListener;
85 import android.view.View;
86 import android.view.ViewAnimationUtils;
87 import android.view.ViewGroup;
88 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
89 import android.view.ViewTreeObserver;
90 import android.view.Window;
91 import android.view.WindowManager;
92 import android.view.accessibility.AccessibilityEvent;
93 import android.view.animation.AccelerateInterpolator;
94 import android.view.animation.DecelerateInterpolator;
95 import android.view.animation.Interpolator;
96 import android.view.inputmethod.InputMethodManager;
97 import android.widget.Advanceable;
98 import android.widget.FrameLayout;
99 import android.widget.ImageView;
100 import android.widget.TextView;
101 import android.widget.Toast;
102 import com.android.launcher3.DropTarget.DragObject;
103 import com.android.launcher3.PagedView.PageSwitchListener;
104 import com.android.launcher3.compat.AppWidgetManagerCompat;
105 import com.android.launcher3.compat.LauncherActivityInfoCompat;
106 import com.android.launcher3.compat.LauncherAppsCompat;
107 import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
108 import com.android.launcher3.compat.PackageInstallerCompat;
109 import com.android.launcher3.compat.UserHandleCompat;
110 import com.android.launcher3.compat.UserManagerCompat;
111 import java.io.DataInputStream;
112 import java.io.DataOutputStream;
113 import java.io.File;
114 import java.io.FileDescriptor;
115 import java.io.FileNotFoundException;
116 import java.io.FileOutputStream;
117 import java.io.IOException;
118 import java.io.PrintWriter;
119 import java.lang.reflect.Field;
120 import java.lang.reflect.InvocationTargetException;
121 import java.lang.reflect.Method;
122 import java.text.DateFormat;
123 import java.util.ArrayList;
124 import java.util.Collection;
125 import java.util.Date;
126 import java.util.HashMap;
127 import java.util.List;
128 import java.util.concurrent.atomic.AtomicInteger;
129
130
131 interface DebugIntents {
132 public static final String DELETE_DATABASE = "com.android.launcher3.action.DELETE_DATABASE";
133
134 public static final String MIGRATE_DATABASE = "com.android.launcher3.action.MIGRATE_DATABASE";
135 }
136
137 /**
138 * Default launcher application.
139 */
140 public class Launcher extends Activity
141 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks,
142 View.OnTouchListener, PageSwitchListener, LauncherProviderChangeListener {
143 static final String TAG = "Launcher";
144 static final boolean LOGD = false;
145
146 static final boolean PROFILE_STARTUP = false;
147 static final boolean DEBUG_WIDGETS = false;
148 static final boolean DEBUG_STRICT_MODE = false;
149 static final boolean DEBUG_RESUME_TIME = false;
150 static final boolean DEBUG_DUMP_LOG = false;
151
152 static final boolean ENABLE_DEBUG_INTENTS = false; // allow DebugIntents to run
153
154 private static final int REQUEST_CREATE_SHORTCUT = 1;
155 private static final int REQUEST_CREATE_APPWIDGET = 5;
156 private static final int REQUEST_PICK_SHORTCUT = 7;
157 private static final int REQUEST_PICK_APPWIDGET = 9;
158 private static final int REQUEST_PICK_WALLPAPER = 10;
159
160 private static final int REQUEST_BIND_APPWIDGET = 11;
161 private static final int REQUEST_RECONFIGURE_APPWIDGET = 12;
162
163 /**
164 * IntentStarter uses request codes starting with this. This must be greater than all activity
165 * request codes used internally.
166 */
167 protected static final int REQUEST_LAST = 100;
168
169 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
170
171 static final int SCREEN_COUNT = 5;
172 static final int DEFAULT_SCREEN = 2;
173
174 private static final String PREFERENCES = "launcher.preferences";
175 // To turn on these properties, type
176 // adb shell setprop log.tag.PROPERTY_NAME [VERBOSE | SUPPRESS]
177 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate";
178 static final String DUMP_STATE_PROPERTY = "launcher_dump_state";
179 static final String DISABLE_ALL_APPS_PROPERTY = "launcher_noallapps";
180
181 // The Intent extra that defines whether to ignore the launch animation
182 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION =
183 "com.android.launcher3.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION";
184
185 // Type: int
186 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
187 // Type: int
188 private static final String RUNTIME_STATE = "launcher.state";
189 // Type: int
190 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container";
191 // Type: int
192 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
193 // Type: int
194 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x";
195 // Type: int
196 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y";
197 // Type: boolean
198 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
199 // Type: long
200 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
201 // Type: int
202 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_span_x";
203 // Type: int
204 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_span_y";
205 // Type: parcelable
206 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_INFO = "launcher.add_widget_info";
207 // Type: parcelable
208 private static final String RUNTIME_STATE_PENDING_ADD_WIDGET_ID = "launcher.add_widget_id";
209 // Type: int[]
210 private static final String RUNTIME_STATE_VIEW_IDS = "launcher.view_ids";
211
212 static final String INTRO_SCREEN_DISMISSED = "launcher.intro_screen_dismissed";
213 static final String FIRST_RUN_ACTIVITY_DISPLAYED = "launcher.first_run_activity_displayed";
214
215 static final String FIRST_LOAD_COMPLETE = "launcher.first_load_complete";
216 static final String ACTION_FIRST_LOAD_COMPLETE =
217 "com.android.launcher3.action.FIRST_LOAD_COMPLETE";
218
219 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon";
220 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME =
221 "com.android.launcher.toolbar_search_icon";
222 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME =
223 "com.android.launcher.toolbar_voice_search_icon";
224
225 public static final String SHOW_WEIGHT_WATCHER = "debug.show_mem";
226 public static final boolean SHOW_WEIGHT_WATCHER_DEFAULT = false;
227
228 public static final String USER_HAS_MIGRATED = "launcher.user_migrated_from_old_data";
229
230 /** The different states that Launcher can be in. */
231 private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
232 private State mState = State.WORKSPACE;
233 private AnimatorSet mStateAnimation;
234
235 private boolean mIsSafeModeEnabled;
236
237 static final int APPWIDGET_HOST_ID = 1024;
238 public static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300;
239 private static final int ON_ACTIVITY_RESULT_ANIMATION_DELAY = 500;
240
241 <<<<<<< LEFT
242 private static final int ACTIVITY_START_DELAY = 1000;
243
244 ||||||| BASE
245 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
246 =======
247
248
249 >>>>>>> RIGHT
250
251 private static final Object sLock = new Object();
252 private static int sScreen = DEFAULT_SCREEN;
253
254 private HashMap<Integer, Integer> mItemIdToViewId = new HashMap<Integer, Integer>();
255 private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
256
257 // How long to wait before the new-shortcut animation automatically pans the workspace
258 private static int NEW_APPS_PAGE_MOVE_DELAY = 500;
259 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 5;
260 private static int NEW_APPS_ANIMATION_DELAY = 500;
261 private static final int SINGLE_FRAME_DELAY = 16;
262
263 private final BroadcastReceiver mCloseSystemDialogsReceiver
264 = new CloseSystemDialogsIntentReceiver();
265 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
266
267 private LayoutInflater mInflater;
268
269 private Workspace mWorkspace;
270 private View mLauncherView;
271 private View mPageIndicators;
272 private DragLayer mDragLayer;
273 private DragController mDragController;
274 private View mWeightWatcher;
275 private LauncherClings mLauncherClings;
276
277 private AppWidgetManagerCompat mAppWidgetManager;
278 private LauncherAppWidgetHost mAppWidgetHost;
279
280 private ItemInfo mPendingAddInfo = new ItemInfo();
281 private AppWidgetProviderInfo mPendingAddWidgetInfo;
282 private int mPendingAddWidgetId = -1;
283
284 private int[] mTmpAddItemCellCoordinates = new int[2];
285
286 private FolderInfo mFolderInfo;
287
288 private Hotseat mHotseat;
289 private ViewGroup mOverviewPanel;
290
291 private View mAllAppsButton;
292
293 private SearchDropTargetBar mSearchDropTargetBar;
294 private AppsCustomizeTabHost mAppsCustomizeTabHost;
295 private AppsCustomizePagedView mAppsCustomizeContent;
296 private boolean mAutoAdvanceRunning = false;
297 private View mQsb;
298
299 private Bundle mSavedState;
300 // We set the state in both onCreate and then onNewIntent in some cases, which causes both
301 // scroll issues (because the workspace may not have been measured yet) and extra work.
302 // Instead, just save the state that we need to restore Launcher to, and commit it in onResume.
303 private State mOnResumeState = State.NONE;
304
305 private SpannableStringBuilder mDefaultKeySsb = null;
306
307 private boolean mWorkspaceLoading = true;
308
309 private boolean mPaused = true;
310 private boolean mRestoring;
311 private boolean mWaitingForResult;
312 private boolean mOnResumeNeedsLoad;
313
314 private ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<Runnable>();
315 private ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<Runnable>();
316
317 private Bundle mSavedInstanceState;
318
319 private LauncherModel mModel;
320 private IconCache mIconCache;
321 private boolean mUserPresent = true;
322 private boolean mVisible = false;
323 private boolean mHasFocus = false;
324 private boolean mAttached = false;
325
326 private static LocaleConfiguration sLocaleConfiguration = null;
327
328 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>();
329
330 private View.OnTouchListener mHapticFeedbackTouchListener;
331
332 // Related to the auto-advancing of widgets
333 private final int ADVANCE_MSG = 1;
334 private final int mAdvanceInterval = 20000;
335 private final int mAdvanceStagger = 250;
336 private long mAutoAdvanceSentTime;
337 private long mAutoAdvanceTimeLeft = -1;
338 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
339 new HashMap<View, AppWidgetProviderInfo>();
340
341 // Determines how long to wait after a rotation before restoring the screen orientation to
342 // match the sensor state.
343 private final int mRestoreScreenOrientationDelay = 500;
344
345 // External icons saved in case of resource changes, orientation, etc.
346 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2];
347 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
348
349 private Drawable mWorkspaceBackgroundDrawable;
350
351 private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
352 private static final boolean DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE = false;
353
354 static final ArrayList<String> sDumpLogs = new ArrayList<String>();
355 static Date sDateStamp = new Date();
356 static DateFormat sDateFormat =
357 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
358 static long sRunStart = System.currentTimeMillis();
359 static final String CORRUPTION_EMAIL_SENT_KEY = "corruptionEmailSent";
360
361 // We only want to get the SharedPreferences once since it does an FS stat each time we get
362 // it from the context.
363 private SharedPreferences mSharedPrefs;
364
365 private static ArrayList<ComponentName> mIntentsOnWorkspaceFromUpgradePath = null;
366
367 // Holds the page that we need to animate to, and the icon views that we need to animate up
368 // when we scroll to that page on resume.
369 private ImageView mFolderIconImageView;
370 private Bitmap mFolderIconBitmap;
371 private Canvas mFolderIconCanvas;
372 private Rect mRectForFolderAnimation = new Rect();
373
374 private BubbleTextView mWaitingForResume;
375
376 private Runnable mBuildLayersRunnable = new Runnable() {
377 public void run() {
378 if (mWorkspace != null) {
379 mWorkspace.buildPageHardwareLayers();
380 }
381 }
382 };
383
384 private static PendingAddArguments sPendingAddItem;
385
386 public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY);
387
388 private static class PendingAddArguments {
389 int requestCode;
390 Intent intent;
391 long container;
392 long screenId;
393 int cellX;
394 int cellY;
395 int appWidgetId;
396 }
397
398 private Stats mStats;
399
400
401 <<<<<<< LEFT
402 FocusIndicatorView mFocusHandler;
403
404
405 ||||||| BASE
406 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
407 =======
408
409
410 >>>>>>> RIGHT
411 static boolean isPropertyEnabled(String propertyName) {
412 return Log.isLoggable(propertyName, Log.VERBOSE);
413 }
414
415 @Override
416 protected void onCreate(Bundle savedInstanceState) {
417 if (DEBUG_STRICT_MODE) {
418 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
419 .detectDiskReads()
420 .detectDiskWrites()
421 .detectNetwork() // or .detectAll() for all detectable problems
422 .penaltyLog()
423 .build());
424 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
425 .detectLeakedSqlLiteObjects()
426 .detectLeakedClosableObjects()
427 .penaltyLog()
428 .penaltyDeath()
429 .build());
430 }
431
432 super.onCreate(savedInstanceState);
433
434 LauncherAppState.setApplicationContext(getApplicationContext());
435 LauncherAppState app = LauncherAppState.getInstance();
436 LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);
437 // Determine the dynamic grid properties
438 Point smallestSize = new Point();
439 Point largestSize = new Point();
440 Point realSize = new Point();
441 Display display = getWindowManager().getDefaultDisplay();
442 display.getCurrentSizeRange(smallestSize, largestSize);
443 display.getRealSize(realSize);
444 DisplayMetrics dm = new DisplayMetrics();
445 display.getMetrics(dm);
446
447 // Lazy-initialize the dynamic grid
448 DeviceProfile grid = app.initDynamicGrid(this,
449 Math.min(smallestSize.x, smallestSize.y),
450 Math.min(largestSize.x, largestSize.y),
451 realSize.x, realSize.y,
452 dm.widthPixels, dm.heightPixels);
453
454 // the LauncherApplication should call this, but in case of Instrumentation it might not be prese🔵
455 mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
456 Context.MODE_PRIVATE);
457 mIsSafeModeEnabled = getPackageManager().isSafeMode();
458 mModel = app.setLauncher(this);
459 mIconCache = app.getIconCache();
460 mIconCache.flushInvalidIcons(grid);
461 mDragController = new DragController(this);
462 mLauncherClings = new LauncherClings(this);
463 mInflater = getLayoutInflater();
464
465 mStats = new Stats(this);
466
467 mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
468
469 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
470 mAppWidgetHost.startListening();
471
472 // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
473 // this also ensures that any synchronous binding below doesn't re-trigger another
474 // LauncherModel load.
475 mPaused = false;
476
477 if (PROFILE_STARTUP) {
478 android.os.Debug.startMethodTracing(
479 Environment.getExternalStorageDirectory() + "/launcher");
480 }
481
482 checkForLocaleChange();
483 setContentView(R.layout.launcher);
484
485 setupViews();
486 grid.layout(this);
487
488 registerContentObservers();
489
490 lockAllApps();
491
492 mSavedState = savedInstanceState;
493 restoreState(mSavedState);
494
495 if (PROFILE_STARTUP) {
496 android.os.Debug.stopMethodTracing();
497 }
498
499 if (!mRestoring) {
500 if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
501 // If the user leaves launcher, then we should just load items asynchronously when
502 // they return.
503 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
504 } else {
505 // We only load the page synchronously if the user rotates (or triggers a
506 // configuration change) while launcher is in the foreground
507 mModel.startLoader(true, mWorkspace.getRestorePage());
508 }
509 }
510
511 // For handling default keys
512 mDefaultKeySsb = new SpannableStringBuilder();
513 Selection.setSelection(mDefaultKeySsb, 0);
514
515 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
516 registerReceiver(mCloseSystemDialogsReceiver, filter);
517
518 updateGlobalIcons();
519
520 // On large interfaces, we want the screen to auto-rotate based on the current orientation
521 unlockScreenOrientation(true);
522
523
524 <<<<<<< LEFT
525 if (shouldShowIntroScreen()) {
526 showIntroScreen();
527 } else {
528 showFirstRunActivity();
529 showFirstRunClings();
530
531 ||||||| BASE
532 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
533 =======
534
535 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
536 // on the device, then we always show the first run cling experience (or if there is no
537 // launcher2). Otherwise, we prompt the user upon started for migration
538 showFirstRunActivity();
539 if (mLauncherClings.shouldShowFirstRunOrMigrationClings()) {
540 if (mModel.canMigrateFromOldLauncherDb(this)) {
541 mLauncherClings.showMigrationCling();
542 } else {
543 mLauncherClings.showFirstRunCling();
544 }
545 } else {
546 mLauncherClings.removeFirstRunAndMigrationClings();
547
548 >>>>>>> RIGHT
549 }
550 }
551
552 @Override
553 public void onLauncherProviderChange() { }
554
555 /** To be overriden by subclasses to hint to Launcher that we have custom content */
556 protected boolean hasCustomContentToLeft() {
557 return false;
558 }
559
560 /**
561 * To be overridden by subclasses to populate the custom content container and call
562 * {@link #addToCustomContentPage}. This will only be invoked if
563 * {@link #hasCustomContentToLeft()} is {@code true}.
564 */
565 protected void populateCustomContentContainer() {
566 }
567
568 /**
569 * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to
570 * ensure the custom content page is added or removed if necessary.
571 */
572 protected void invalidateHasCustomContentToLeft() {
573 if (mWorkspace == null || mWorkspace.getScreenOrder().isEmpty()) {
574 // Not bound yet, wait for bindScreens to be called.
575 return;
576 }
577
578 if (!mWorkspace.hasCustomContent() && hasCustomContentToLeft()) {
579 // Create the custom content page and call the subclass to populate it.
580 mWorkspace.createCustomContentContainer();
581 populateCustomContentContainer();
582 } else if (mWorkspace.hasCustomContent() && !hasCustomContentToLeft()) {
583 mWorkspace.removeCustomContentPage();
584 }
585 }
586
587 private void updateGlobalIcons() {
588 boolean searchVisible = false;
589 boolean voiceVisible = false;
590 // If we have a saved version of these external icons, we load them up immediately
591 int coi = getCurrentOrientationIndexForGlobalIcons();
592 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null) {
593 searchVisible = updateGlobalSearchIcon();
594 voiceVisible = updateVoiceSearchIcon(searchVisible);
595 }
596 if (sGlobalSearchIcon[coi] != null) {
597 updateGlobalSearchIcon(sGlobalSearchIcon[coi]);
598 searchVisible = true;
599 }
600 if (sVoiceSearchIcon[coi] != null) {
601 updateVoiceSearchIcon(sVoiceSearchIcon[coi]);
602 voiceVisible = true;
603 }
604 if (mSearchDropTargetBar != null) {
605 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
606 }
607 }
608
609 private void checkForLocaleChange() {
610 if (sLocaleConfiguration == null) {
611 new AsyncTask<Void, Void, LocaleConfiguration>() {
612 @Override
613 protected LocaleConfiguration doInBackground(Void... unused) {
614 LocaleConfiguration localeConfiguration = new LocaleConfiguration();
615 readConfiguration(Launcher.this, localeConfiguration);
616 return localeConfiguration;
617 }
618
619 @Override
620 protected void onPostExecute(LocaleConfiguration result) {
621 sLocaleConfiguration = result;
622 checkForLocaleChange(); // recursive, but now with a locale configuration
623 }
624 }.execute();
625 return;
626 }
627
628 final Configuration configuration = getResources().getConfiguration();
629
630 final String previousLocale = sLocaleConfiguration.locale;
631 final String locale = configuration.locale.toString();
632
633 final int previousMcc = sLocaleConfiguration.mcc;
634 final int mcc = configuration.mcc;
635
636 final int previousMnc = sLocaleConfiguration.mnc;
637 final int mnc = configuration.mnc;
638
639 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMn🔵
640
641 if (localeChanged) {
642 sLocaleConfiguration.locale = locale;
643 sLocaleConfiguration.mcc = mcc;
644 sLocaleConfiguration.mnc = mnc;
645
646 mIconCache.flush();
647
648 final LocaleConfiguration localeConfiguration = sLocaleConfiguration;
649 new AsyncTask<Void, Void, Void>() {
650 public Void doInBackground(Void ... args) {
651 writeConfiguration(Launcher.this, localeConfiguration);
652 return null;
653 }
654 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
655 }
656 }
657
658 private static class LocaleConfiguration {
659 public String locale;
660 public int mcc = -1;
661 public int mnc = -1;
662 }
663
664 private static void readConfiguration(Context context, LocaleConfiguration configuration) {
665 DataInputStream in = null;
666 try {
667 in = new DataInputStream(context.openFileInput(PREFERENCES));
668 configuration.locale = in.readUTF();
669 configuration.mcc = in.readInt();
670 configuration.mnc = in.readInt();
671 } catch (FileNotFoundException e) {
672 // Ignore
673 } catch (IOException e) {
674 // Ignore
675 } finally {
676 if (in != null) {
677 try {
678 in.close();
679 } catch (IOException e) {
680 // Ignore
681 }
682 }
683 }
684 }
685
686 private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
687 DataOutputStream out = null;
688 try {
689 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
690 out.writeUTF(configuration.locale);
691 out.writeInt(configuration.mcc);
692 out.writeInt(configuration.mnc);
693 out.flush();
694 } catch (FileNotFoundException e) {
695 // Ignore
696 } catch (IOException e) {
697 //noinspection ResultOfMethodCallIgnored
698 context.getFileStreamPath(PREFERENCES).delete();
699 } finally {
700 if (out != null) {
701 try {
702 out.close();
703 } catch (IOException e) {
704 // Ignore
705 }
706 }
707 }
708 }
709
710 public Stats getStats() {
711 return mStats;
712 }
713
714 public LayoutInflater getInflater() {
715 return mInflater;
716 }
717
718 boolean isDraggingEnabled() {
719 // We prevent dragging when we are loading the workspace as it is possible to pick up a view
720 // that is subsequently removed from the workspace in startBinding().
721 return !mModel.isLoadingWorkspace();
722 }
723
724 static int getScreen() {
725 synchronized (sLock) {
726 return sScreen;
727 }
728 }
729
730 static void setScreen(int screen) {
731 synchronized (sLock) {
732 sScreen = screen;
733 }
734 }
735
736 public static int generateViewId() {
737 if (Build.VERSION.SDK_INT >= 17) {
738 return View.generateViewId();
739 } else {
740 // View.generateViewId() is not available. The following fallback logic is a copy
741 // of its implementation.
742 for (;;) {
743 final int result = sNextGeneratedId.get();
744 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
745 int newValue = result + 1;
746 if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0.
747 if (sNextGeneratedId.compareAndSet(result, newValue)) {
748 return result;
749 }
750 }
751 }
752 }
753
754 public int getViewIdForItem(ItemInfo info) {
755 // This cast is safe given the > 2B range for int.
756 int itemId = (int) info.id;
757 if (mItemIdToViewId.containsKey(itemId)) {
758 return mItemIdToViewId.get(itemId);
759 }
760 int viewId = generateViewId();
761 mItemIdToViewId.put(itemId, viewId);
762 return viewId;
763 }
764
765 /**
766 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
767 * a configuration step, this allows the proper animations to run after other transitions.
768 */
769 private long completeAdd(PendingAddArguments args) {
770 long screenId = args.screenId;
771 if (args.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
772 // When the screen id represents an actual screen (as opposed to a rank) we make sure
773 // that the drop page actually exists.
774 screenId = ensurePendingDropLayoutExists(args.screenId);
775 }
776
777 switch (args.requestCode) {
778 case REQUEST_CREATE_SHORTCUT:
779 completeAddShortcut(args.intent, args.container, screenId, args.cellX,
780 args.cellY);
781 break;
782 case REQUEST_CREATE_APPWIDGET:
783 completeAddAppWidget(args.appWidgetId, args.container, screenId, null, null);
784 break;
785 case REQUEST_RECONFIGURE_APPWIDGET:
786 completeRestoreAppWidget(args.appWidgetId);
787 break;
788 }
789 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen,
790 // if you turned the screen off and then back while in All Apps, Launcher would not
791 // return to the workspace. Clearing mAddInfo.container here fixes this issue
792 resetAddInfo();
793 return screenId;
794 }
795
796 @Override
797 protected void onActivityResult(
798 final int requestCode, final int resultCode, final Intent data) {
799 // Reset the startActivity waiting flag
800 setWaitingForResult(false);
801 final int pendingAddWidgetId = mPendingAddWidgetId;
802 mPendingAddWidgetId = -1;
803
804 Runnable exitSpringLoaded = new Runnable() {
805 @Override
806 public void run() {
807 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
808 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
809 }
810 };
811
812 if (requestCode == REQUEST_BIND_APPWIDGET) {
813 final int appWidgetId = data != null ?
814 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1;
815 if (resultCode == RESULT_CANCELED) {
816 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId);
817 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
818 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
819 } else if (resultCode == RESULT_OK) {
820 addAppWidgetImpl(appWidgetId, mPendingAddInfo, null,
821 mPendingAddWidgetInfo, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
822 }
823 return;
824 } else if (requestCode == REQUEST_PICK_WALLPAPER) {
825 if (resultCode == RESULT_OK && mWorkspace.isInOverviewMode()) {
826 mWorkspace.exitOverviewMode(false);
827 }
828 return;
829 }
830
831 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET ||
832 requestCode == REQUEST_CREATE_APPWIDGET);
833
834 final boolean workspaceLocked = isWorkspaceLocked();
835 // We have special handling for widgets
836 if (isWidgetDrop) {
837 final int appWidgetId;
838 int widgetId = data != null ? data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
839 : -1;
840 if (widgetId < 0) {
841 appWidgetId = pendingAddWidgetId;
842 } else {
843 appWidgetId = widgetId;
844 }
845
846 final int result;
847 if (appWidgetId < 0 || resultCode == RESULT_CANCELED) {
848 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not " +
849 "returned from the widget configuration activity.");
850 result = RESULT_CANCELED;
851 completeTwoStageWidgetDrop(result, appWidgetId);
852 final Runnable onComplete = new Runnable() {
853 @Override
854 public void run() {
855 exitSpringLoadedDragModeDelayed(false, 0, null);
856 }
857 };
858 if (workspaceLocked) {
859 // No need to remove the empty screen if we're mid-binding, as the
860 // the bind will not add the empty screen.
861 mWorkspace.postDelayed(onComplete, ON_ACTIVITY_RESULT_ANIMATION_DELAY);
862 } else {
863 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
864 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
865 }
866 } else {
867 if (!workspaceLocked) {
868 if (mPendingAddInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
869 // When the screen id represents an actual screen (as opposed to a rank)
870 // we make sure that the drop page actually exists.
871 mPendingAddInfo.screenId =
872 ensurePendingDropLayoutExists(mPendingAddInfo.screenId);
873 }
874 final CellLayout dropLayout = mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
875
876 dropLayout.setDropPending(true);
877 final Runnable onComplete = new Runnable() {
878 @Override
879 public void run() {
880 completeTwoStageWidgetDrop(resultCode, appWidgetId);
881 dropLayout.setDropPending(false);
882 }
883 };
884 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete,
885 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
886 } else {
887 PendingAddArguments args = preparePendingAddArgs(requestCode, data, appWidgetId,
888 mPendingAddInfo);
889 sPendingAddItem = args;
890 }
891 }
892 return;
893 }
894
895 if (requestCode == REQUEST_RECONFIGURE_APPWIDGET) {
896 if (resultCode == RESULT_OK) {
897 // Update the widget view.
898 PendingAddArguments args = preparePendingAddArgs(requestCode, data,
899 pendingAddWidgetId, mPendingAddInfo);
900 if (workspaceLocked) {
901 sPendingAddItem = args;
902 } else {
903 completeAdd(args);
904 }
905 }
906 // Leave the widget in the pending state if the user canceled the configure.
907 return;
908 }
909
910 // The pattern used here is that a user PICKs a specific application,
911 // which, depending on the target, might need to CREATE the actual target.
912
913 // For example, the user would PICK_SHORTCUT for "Music playlist", and we
914 // launch over to the Music app to actually CREATE_SHORTCUT.
915 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) {
916 final PendingAddArguments args = preparePendingAddArgs(requestCode, data, -1,
917 mPendingAddInfo);
918 if (isWorkspaceLocked()) {
919 sPendingAddItem = args;
920 } else {
921 completeAdd(args);
922 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
923 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
924 }
925 } else if (resultCode == RESULT_CANCELED) {
926 mWorkspace.removeExtraEmptyScreenDelayed(true, exitSpringLoaded,
927 ON_ACTIVITY_RESULT_ANIMATION_DELAY, false);
928 }
929 mDragLayer.clearAnimatedView();
930 }
931
932 private PendingAddArguments preparePendingAddArgs(int requestCode, Intent data, int
933 appWidgetId, ItemInfo info) {
934 PendingAddArguments args = new PendingAddArguments();
935 args.requestCode = requestCode;
936 args.intent = data;
937 args.container = info.container;
938 args.screenId = info.screenId;
939 args.cellX = info.cellX;
940 args.cellY = info.cellY;
941 args.appWidgetId = appWidgetId;
942 return args;
943 }
944
945 /**
946 * Check to see if a given screen id exists. If not, create it at the end, return the new id.
947 *
948 * @param screenId the screen id to check
949 * @return the new screen, or screenId if it exists
950 */
951 private long ensurePendingDropLayoutExists(long screenId) {
952 CellLayout dropLayout =
953 (CellLayout) mWorkspace.getScreenWithId(screenId);
954 if (dropLayout == null) {
955 // it's possible that the add screen was removed because it was
956 // empty and a re-bind occurred
957 mWorkspace.addExtraEmptyScreen();
958 return mWorkspace.commitExtraEmptyScreen();
959 } else {
960 return screenId;
961 }
962 }
963
964 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) {
965 CellLayout cellLayout =
966 (CellLayout) mWorkspace.getScreenWithId(mPendingAddInfo.screenId);
967 Runnable onCompleteRunnable = null;
968 int animationType = 0;
969
970 AppWidgetHostView boundWidget = null;
971 if (resultCode == RESULT_OK) {
972 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION;
973 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId,
974 mPendingAddWidgetInfo);
975 boundWidget = layout;
976 onCompleteRunnable = new Runnable() {
977 @Override
978 public void run() {
979 completeAddAppWidget(appWidgetId, mPendingAddInfo.container,
980 mPendingAddInfo.screenId, layout, null);
981 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED),
982 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null);
983 }
984 };
985 } else if (resultCode == RESULT_CANCELED) {
986 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
987 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION;
988 }
989 if (mDragLayer.getAnimatedView() != null) {
990 mWorkspace.animateWidgetDrop(mPendingAddInfo, cellLayout,
991 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable,
992 animationType, boundWidget, true);
993 } else if (onCompleteRunnable != null) {
994 // The animated view may be null in the case of a rotation during widget configuration
995 onCompleteRunnable.run();
996 }
997 }
998
999 @Override
1000 protected void onStop() {
1001 super.onStop();
1002 FirstFrameAnimatorHelper.setIsVisible(false);
1003 }
1004
1005 @Override
1006 protected void onStart() {
1007 super.onStart();
1008 FirstFrameAnimatorHelper.setIsVisible(true);
1009 }
1010
1011 @Override
1012 protected void onResume() {
1013 long startTime = 0;
1014 if (DEBUG_RESUME_TIME) {
1015 startTime = System.currentTimeMillis();
1016 Log.v(TAG, "Launcher.onResume()");
1017 }
1018 super.onResume();
1019
1020 // Restore the previous launcher state
1021 if (mOnResumeState == State.WORKSPACE) {
1022 showWorkspace(false);
1023 } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
1024 showAllApps(false, mAppsCustomizeContent.getContentType(), false);
1025 }
1026 mOnResumeState = State.NONE;
1027
1028 // Background was set to gradient in onPause(), restore to black if in all apps.
1029 setWorkspaceBackground(mState == State.WORKSPACE);
1030
1031 mPaused = false;
1032 if (mRestoring || mOnResumeNeedsLoad) {
1033 setWorkspaceLoading(true);
1034 mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
1035 mRestoring = false;
1036 mOnResumeNeedsLoad = false;
1037 }
1038 if (mBindOnResumeCallbacks.size() > 0) {
1039 // We might have postponed some bind calls until onResume (see waitUntilResume) --
1040 // execute them here
1041 long startTimeCallbacks = 0;
1042 if (DEBUG_RESUME_TIME) {
1043 startTimeCallbacks = System.currentTimeMillis();
1044 }
1045
1046 if (mAppsCustomizeContent != null) {
1047 mAppsCustomizeContent.setBulkBind(true);
1048 }
1049 for (int i = 0; i < mBindOnResumeCallbacks.size(); i++) {
1050 mBindOnResumeCallbacks.get(i).run();
1051 }
1052 if (mAppsCustomizeContent != null) {
1053 mAppsCustomizeContent.setBulkBind(false);
1054 }
1055 mBindOnResumeCallbacks.clear();
1056 if (DEBUG_RESUME_TIME) {
1057 Log.d(TAG, "Time spent processing callbacks in onResume: " +
1058 (System.currentTimeMillis() - startTimeCallbacks));
1059 }
1060 }
1061 if (mOnResumeCallbacks.size() > 0) {
1062 for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
1063 mOnResumeCallbacks.get(i).run();
1064 }
1065 mOnResumeCallbacks.clear();
1066 }
1067
1068 // Reset the pressed state of icons that were locked in the press state while activities
1069 // were launching
1070 if (mWaitingForResume != null) {
1071 // Resets the previous workspace icon press state
1072 mWaitingForResume.setStayPressed(false);
1073 }
1074
1075 // It is possible that widgets can receive updates while launcher is not in the foreground.
1076 // Consequently, the widgets will be inflated in the orientation of the foreground activity
1077 // (framework issue). On resuming, we ensure that any widgets are inflated for the current
1078 // orientation.
1079 getWorkspace().reinflateWidgetsIfNecessary();
1080
1081 // Process any items that were added while Launcher was away.
1082 InstallShortcutReceiver.disableAndFlushInstallQueue(this);
1083
1084 // Update the voice search button proxy
1085 updateVoiceButtonProxyVisible(false);
1086
1087 // Again, as with the above scenario, it's possible that one or more of the global icons
1088 // were updated in the wrong orientation.
1089 updateGlobalIcons();
1090 if (DEBUG_RESUME_TIME) {
1091 Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
1092 }
1093
1094 if (mWorkspace.getCustomContentCallbacks() != null) {
1095 // If we are resuming and the custom content is the current page, we call onShow().
1096 // It is also poassible that onShow will instead be called slightly after first layout
1097 // if PagedView#setRestorePage was set to the custom content page in onCreate().
1098 if (mWorkspace.isOnOrMovingToCustomContent()) {
1099 mWorkspace.getCustomContentCallbacks().onShow(true);
1100 }
1101 }
1102 mWorkspace.updateInteractionForState();
1103 mWorkspace.onResume();
1104
1105 PackageInstallerCompat.getInstance(this).onResume();
1106 }
1107
1108 @Override
1109 protected void onPause() {
1110 // Ensure that items added to Launcher are queued until Launcher returns
1111 InstallShortcutReceiver.enableInstallQueue();
1112 PackageInstallerCompat.getInstance(this).onPause();
1113
1114 super.onPause();
1115 mPaused = true;
1116 mDragController.cancelDrag();
1117 mDragController.resetLastGestureUpTime();
1118
1119 // We call onHide() aggressively. The custom content callbacks should be able to
1120 // debounce excess onHide calls.
1121 if (mWorkspace.getCustomContentCallbacks() != null) {
1122 mWorkspace.getCustomContentCallbacks().onHide();
1123 }
1124 }
1125
1126 QSBScroller mQsbScroller = new QSBScroller() {
1127 int scrollY = 0;
1128
1129 @Override
1130 public void setScrollY(int scroll) {
1131 scrollY = scroll;
1132
1133 if (mWorkspace.isOnOrMovingToCustomContent()) {
1134 mSearchDropTargetBar.setTranslationY(- scrollY);
1135 getQsbBar().setTranslationY(-scrollY);
1136 }
1137 }
1138 };
1139
1140 public void resetQSBScroll() {
1141 mSearchDropTargetBar.animate().translationY(0).start();
1142 getQsbBar().animate().translationY(0).start();
1143 }
1144
1145 public interface CustomContentCallbacks {
1146 // Custom content is completely shown. {@code fromResume} indicates whether this was caused
1147 // by a onResume or by scrolling otherwise.
1148 public void onShow(boolean fromResume);
1149
1150 // Custom content is completely hidden
1151 public void onHide();
1152
1153 // Custom content scroll progress changed. From 0 (not showing) to 1 (fully showing).
1154 public void onScrollProgressChanged(float progress);
1155
1156 // Indicates whether the user is allowed to scroll away from the custom content.
1157 boolean isScrollingAllowed();
1158 }
1159
1160 protected boolean hasSettings() {
1161 return false;
1162 }
1163
1164 public interface QSBScroller {
1165 public void setScrollY(int scrollY);
1166 }
1167
1168 public QSBScroller addToCustomContentPage(View customContent,
1169 CustomContentCallbacks callbacks, String description) {
1170 mWorkspace.addToCustomContentPage(customContent, callbacks, description);
1171 return mQsbScroller;
1172 }
1173
1174 // The custom content needs to offset its content to account for the QSB
1175 public int getTopOffsetForCustomContent() {
1176 return mWorkspace.getPaddingTop();
1177 }
1178
1179 @Override
1180 public Object onRetainNonConfigurationInstance() {
1181 // Flag the loader to stop early before switching
1182 if (mModel.isCurrentCallbacks(this)) {
1183 mModel.stopLoader();
1184 }
1185 if (mAppsCustomizeContent != null) {
1186 mAppsCustomizeContent.surrender();
1187 }
1188 return Boolean.TRUE;
1189 }
1190
1191 // We can't hide the IME if it was forced open. So don't bother
1192 @Override
1193 public void onWindowFocusChanged(boolean hasFocus) {
1194 super.onWindowFocusChanged(hasFocus);
1195 mHasFocus = hasFocus;
1196 }
1197
1198 private boolean acceptFilter() {
1199 final InputMethodManager inputManager = (InputMethodManager)
1200 getSystemService(Context.INPUT_METHOD_SERVICE);
1201 return !inputManager.isFullscreenMode();
1202 }
1203
1204 @Override
1205 public boolean onKeyDown(int keyCode, KeyEvent event) {
1206 final int uniChar = event.getUnicodeChar();
1207 final boolean handled = super.onKeyDown(keyCode, event);
1208 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
1209 if (!handled && acceptFilter() && isKeyNotWhitespace) {
1210 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
1211 keyCode, event);
1212 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
1213 // something usable has been typed - start a search
1214 // the typed text will be retrieved and cleared by
1215 // showSearchDialog()
1216 // If there are multiple keystrokes before the search dialog takes focus,
1217 // onSearchRequested() will be called for every keystroke,
1218 // but it is idempotent, so it's fine.
1219 return onSearchRequested();
1220 }
1221 }
1222
1223 // Eat the long press event so the keyboard doesn't come up.
1224 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
1225 return true;
1226 }
1227
1228 return handled;
1229 }
1230
1231 private String getTypedText() {
1232 return mDefaultKeySsb.toString();
1233 }
1234
1235 private void clearTypedText() {
1236 mDefaultKeySsb.clear();
1237 mDefaultKeySsb.clearSpans();
1238 Selection.setSelection(mDefaultKeySsb, 0);
1239 }
1240
1241 /**
1242 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type
1243 * State
1244 */
1245 private static State intToState(int stateOrdinal) {
1246 State state = State.WORKSPACE;
1247 final State[] stateValues = State.values();
1248 for (int i = 0; i < stateValues.length; i++) {
1249 if (stateValues[i].ordinal() == stateOrdinal) {
1250 state = stateValues[i];
1251 break;
1252 }
1253 }
1254 return state;
1255 }
1256
1257 /**
1258 * Restores the previous state, if it exists.
1259 *
1260 * @param savedState The previous state.
1261 */
1262 @SuppressWarnings("unchecked")
1263 private void restoreState(Bundle savedState) {
1264 if (savedState == null) {
1265 return;
1266 }
1267
1268 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
1269 if (state == State.APPS_CUSTOMIZE) {
1270 mOnResumeState = State.APPS_CUSTOMIZE;
1271 }
1272
1273 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN,
1274 PagedView.INVALID_RESTORE_PAGE);
1275 if (currentScreen != PagedView.INVALID_RESTORE_PAGE) {
1276 mWorkspace.setRestorePage(currentScreen);
1277 }
1278
1279 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1);
1280 final long pendingAddScreen = savedState.getLong(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
1281
1282 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) {
1283 mPendingAddInfo.container = pendingAddContainer;
1284 mPendingAddInfo.screenId = pendingAddScreen;
1285 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
1286 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
1287 mPendingAddInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
1288 mPendingAddInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
1289 mPendingAddWidgetInfo = savedState.getParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO);
1290 mPendingAddWidgetId = savedState.getInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID);
1291 setWaitingForResult(true);
1292 mRestoring = true;
1293 }
1294
1295 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
1296 if (renameFolder) {
1297 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
1298 mFolderInfo = mModel.getFolderById(this, sFolders, id);
1299 mRestoring = true;
1300 }
1301
1302 // Restore the AppsCustomize tab
1303 if (mAppsCustomizeTabHost != null) {
1304 String curTab = savedState.getString("apps_customize_currentTab");
1305 if (curTab != null) {
1306 mAppsCustomizeTabHost.setContentTypeImmediate(
1307 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
1308 mAppsCustomizeContent.loadAssociatedPages(
1309 mAppsCustomizeContent.getCurrentPage());
1310 }
1311
1312 int currentIndex = savedState.getInt("apps_customize_currentIndex");
1313 mAppsCustomizeContent.restorePageForIndex(currentIndex);
1314 }
1315 mItemIdToViewId = (HashMap<Integer, Integer>)
1316 savedState.getSerializable(RUNTIME_STATE_VIEW_IDS);
1317 }
1318
1319 /**
1320 * Finds all the views we need and configure them properly.
1321 */
1322 private void setupViews() {
1323 final DragController dragController = mDragController;
1324
1325 mLauncherView = findViewById(R.id.launcher);
1326 mFocusHandler = (FocusIndicatorView) findViewById(R.id.focus_indicator);
1327 mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
1328 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
1329
1330 <<<<<<< LEFT
1331 mWorkspace.setPageSwitchListener(this);
1332
1333 ||||||| BASE
1334 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
1335 =======
1336
1337
1338 >>>>>>> RIGHT
1339 mPageIndicators = mDragLayer.findViewById(R.id.page_indicator);
1340
1341 mLauncherView.setSystemUiVisibility(
1342 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1343 mWorkspaceBackgroundDrawable = getResources().getDrawable(R.drawable.workspace_bg);
1344
1345 // Setup the drag layer
1346 mDragLayer.setup(this, dragController);
1347
1348 // Setup the hotseat
1349 mHotseat = (Hotseat) findViewById(R.id.hotseat);
1350 if (mHotseat != null) {
1351 mHotseat.setup(this);
1352 mHotseat.setOnLongClickListener(this);
1353 }
1354
1355 mOverviewPanel = (ViewGroup) findViewById(R.id.overview_panel);
1356 View widgetButton = findViewById(R.id.widget_button);
1357 widgetButton.setOnClickListener(new OnClickListener() {
1358 @Override
1359 public void onClick(View arg0) {
1360 if (!mWorkspace.isSwitchingState()) {
1361 onClickAddWidgetButton(arg0);
1362 }
1363 }
1364 });
1365 widgetButton.setOnTouchListener(getHapticFeedbackTouchListener());
1366
1367 View wallpaperButton = findViewById(R.id.wallpaper_button);
1368 wallpaperButton.setOnClickListener(new OnClickListener() {
1369 @Override
1370 public void onClick(View arg0) {
1371 if (!mWorkspace.isSwitchingState()) {
1372 onClickWallpaperPicker(arg0);
1373 }
1374 }
1375 });
1376 wallpaperButton.setOnTouchListener(getHapticFeedbackTouchListener());
1377
1378 View settingsButton = findViewById(R.id.settings_button);
1379 if (hasSettings()) {
1380 settingsButton.setOnClickListener(new OnClickListener() {
1381 @Override
1382 public void onClick(View arg0) {
1383 if (!mWorkspace.isSwitchingState()) {
1384 onClickSettingsButton(arg0);
1385 }
1386 }
1387 });
1388 settingsButton.setOnTouchListener(getHapticFeedbackTouchListener());
1389 } else {
1390 settingsButton.setVisibility(View.GONE);
1391 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) widgetButton.getLayoutParams();
1392 lp.gravity = Gravity.END | Gravity.TOP;
1393 widgetButton.requestLayout();
1394 }
1395
1396 mOverviewPanel.setAlpha(0f);
1397
1398 // Setup the workspace
1399 mWorkspace.setHapticFeedbackEnabled(false);
1400 mWorkspace.setOnLongClickListener(this);
1401 mWorkspace.setup(dragController);
1402 dragController.addDragListener(mWorkspace);
1403
1404 // Get the search/delete bar
1405 mSearchDropTargetBar = (SearchDropTargetBar)
1406 mDragLayer.findViewById(R.id.search_drop_target_bar);
1407
1408 // Setup AppsCustomize
1409 mAppsCustomizeTabHost = (AppsCustomizeTabHost) findViewById(R.id.apps_customize_pane);
1410 mAppsCustomizeContent = (AppsCustomizePagedView)
1411 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content);
1412 mAppsCustomizeContent.setup(this, dragController);
1413
1414 // Setup the drag controller (drop targets have to be added in reverse order in priority)
1415 dragController.setDragScoller(mWorkspace);
1416 dragController.setScrollView(mDragLayer);
1417 dragController.setMoveTarget(mWorkspace);
1418 dragController.addDropTarget(mWorkspace);
1419 if (mSearchDropTargetBar != null) {
1420 mSearchDropTargetBar.setup(this, dragController);
1421 }
1422
1423 if (getResources().getBoolean(R.bool.debug_memory_enabled)) {
1424 Log.v(TAG, "adding WeightWatcher");
1425 mWeightWatcher = new WeightWatcher(this);
1426 mWeightWatcher.setAlpha(0.5f);
1427 ((FrameLayout) mLauncherView).addView(mWeightWatcher,
1428 new FrameLayout.LayoutParams(
1429 FrameLayout.LayoutParams.MATCH_PARENT,
1430 FrameLayout.LayoutParams.WRAP_CONTENT,
1431 Gravity.BOTTOM)
1432 );
1433
1434 boolean show = shouldShowWeightWatcher();
1435 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
1436 }
1437 }
1438
1439 /**
1440 * Sets the all apps button. This method is called from {@link Hotseat}.
1441 */
1442 public void setAllAppsButton(View allAppsButton) {
1443 mAllAppsButton = allAppsButton;
1444 }
1445
1446 public View getAllAppsButton() {
1447 return mAllAppsButton;
1448 }
1449
1450 /**
1451 * Creates a view representing a shortcut.
1452 *
1453 * @param info The data structure describing the shortcut.
1454 *
1455 * @return A View inflated from R.layout.application.
1456 */
1457 View createShortcut(ShortcutInfo info) {
1458 return createShortcut(R.layout.application,
1459 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info);
1460 }
1461
1462 /**
1463 * Creates a view representing a shortcut inflated from the specified resource.
1464 *
1465 * @param layoutResId The id of the XML layout used to create the shortcut.
1466 * @param parent The group the shortcut belongs to.
1467 * @param info The data structure describing the shortcut.
1468 *
1469 * @return A View inflated from layoutResId.
1470 */
1471 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
1472 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false);
1473 favorite.applyFromShortcutInfo(info, mIconCache, true);
1474 favorite.setOnClickListener(this);
1475 favorite.setOnFocusChangeListener(mFocusHandler);
1476 return favorite;
1477 }
1478
1479 /**
1480 * Add a shortcut to the workspace.
1481 *
1482 * @param data The intent describing the shortcut.
1483 * @param cellInfo The position on screen where to create the shortcut.
1484 */
1485 private void completeAddShortcut(Intent data, long container, long screenId, int cellX,
1486 int cellY) {
1487 int[] cellXY = mTmpAddItemCellCoordinates;
1488 int[] touchXY = mPendingAddInfo.dropPos;
1489 CellLayout layout = getCellLayout(container, screenId);
1490
1491 boolean foundCellSpan = false;
1492
1493 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null);
1494 if (info == null) {
1495 return;
1496 }
1497 final View view = createShortcut(info);
1498
1499 // First we check if we already know the exact location where we want to add this item.
1500 if (cellX >= 0 && cellY >= 0) {
1501 cellXY[0] = cellX;
1502 cellXY[1] = cellY;
1503 foundCellSpan = true;
1504
1505 // If appropriate, either create a folder or add to an existing folder
1506 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0,
1507 true, null,null)) {
1508 return;
1509 }
1510 DragObject dragObject = new DragObject();
1511 dragObject.dragInfo = info;
1512 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject,
1513 true)) {
1514 return;
1515 }
1516 } else if (touchXY != null) {
1517 // when dragging and dropping, just find the closest free spot
1518 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY);
1519 foundCellSpan = (result != null);
1520 } else {
1521 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1);
1522 }
1523
1524 if (!foundCellSpan) {
1525 showOutOfSpaceMessage(isHotseatLayout(layout));
1526 return;
1527 }
1528
1529 LauncherModel.addItemToDatabase(this, info, container, screenId, cellXY[0], cellXY[1], false);
1530
1531 if (!mRestoring) {
1532 mWorkspace.addInScreen(view, container, screenId, cellXY[0], cellXY[1], 1, 1,
1533 isWorkspaceLocked());
1534 }
1535 }
1536
1537 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth,
1538 int minHeight) {
1539 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null);
1540 // We want to account for the extra amount of padding that we are adding to the widget
1541 // to ensure that it gets the full amount of space that it has requested
1542 int requiredWidth = minWidth + padding.left + padding.right;
1543 int requiredHeight = minHeight + padding.top + padding.bottom;
1544 return CellLayout.rectToCell(requiredWidth, requiredHeight, null);
1545 }
1546
1547 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) {
1548 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight);
1549 }
1550
1551 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) {
1552 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight);
1553 }
1554
1555 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) {
1556 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight);
1557 }
1558
1559 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) {
1560 return getSpanForWidget(context, info.componentName, info.minResizeWidth,
1561 info.minResizeHeight);
1562 }
1563
1564 /**
1565 * Add a widget to the workspace.
1566 *
1567 * @param appWidgetId The app widget id
1568 * @param cellInfo The position on screen where to create the widget.
1569 */
1570 private void completeAddAppWidget(final int appWidgetId, long container, long screenId,
1571 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) {
1572 if (appWidgetInfo == null) {
1573 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
1574 }
1575
1576 // Calculate the grid spans needed to fit this widget
1577 CellLayout layout = getCellLayout(container, screenId);
1578
1579 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo);
1580 int[] spanXY = getSpanForWidget(this, appWidgetInfo);
1581
1582 // Try finding open space on Launcher screen
1583 // We have saved the position to which the widget was dragged-- this really only matters
1584 // if we are placing widgets on a "spring-loaded" screen
1585 int[] cellXY = mTmpAddItemCellCoordinates;
1586 int[] touchXY = mPendingAddInfo.dropPos;
1587 int[] finalSpan = new int[2];
1588 boolean foundCellSpan = false;
1589 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) {
1590 cellXY[0] = mPendingAddInfo.cellX;
1591 cellXY[1] = mPendingAddInfo.cellY;
1592 spanXY[0] = mPendingAddInfo.spanX;
1593 spanXY[1] = mPendingAddInfo.spanY;
1594 foundCellSpan = true;
1595 } else if (touchXY != null) {
1596 // when dragging and dropping, just find the closest free spot
1597 int[] result = layout.findNearestVacantArea(
1598 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0],
1599 spanXY[1], cellXY, finalSpan);
1600 spanXY[0] = finalSpan[0];
1601 spanXY[1] = finalSpan[1];
1602 foundCellSpan = (result != null);
1603 } else {
1604 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]);
1605 }
1606
1607 if (!foundCellSpan) {
1608 if (appWidgetId != -1) {
1609 // Deleting an app widget ID is a void call but writes to disk before returning
1610 // to the caller...
1611 new AsyncTask<Void, Void, Void>() {
1612 public Void doInBackground(Void ... args) {
1613 mAppWidgetHost.deleteAppWidgetId(appWidgetId);
1614 return null;
1615 }
1616 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
1617 }
1618 showOutOfSpaceMessage(isHotseatLayout(layout));
1619 return;
1620 }
1621
1622 // Build Launcher-specific widget info and save to database
1623 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId,
1624 appWidgetInfo.provider);
1625 launcherInfo.spanX = spanXY[0];
1626 launcherInfo.spanY = spanXY[1];
1627 launcherInfo.minSpanX = mPendingAddInfo.minSpanX;
1628 launcherInfo.minSpanY = mPendingAddInfo.minSpanY;
1629 launcherInfo.user = mAppWidgetManager.getUser(appWidgetInfo);
1630
1631 LauncherModel.addItemToDatabase(this, launcherInfo,
1632 container, screenId, cellXY[0], cellXY[1], false);
1633
1634 if (!mRestoring) {
1635 if (hostView == null) {
1636 // Perform actual inflation because we're live
1637 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
1638 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
1639 } else {
1640 // The AppWidgetHostView has already been inflated and instantiated
1641 launcherInfo.hostView = hostView;
1642 }
1643
1644 launcherInfo.hostView.setTag(launcherInfo);
1645 launcherInfo.hostView.setVisibility(View.VISIBLE);
1646 launcherInfo.notifyWidgetSizeChanged(this);
1647
1648 mWorkspace.addInScreen(launcherInfo.hostView, container, screenId, cellXY[0], cellXY[1],
1649 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
1650
1651 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo);
1652 }
1653 resetAddInfo();
1654 }
1655
1656 private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
1657 @Override
1658 public void onReceive(Context context, Intent intent) {
1659 final String action = intent.getAction();
1660 if (Intent.ACTION_SCREEN_OFF.equals(action)) {
1661 mUserPresent = false;
1662 mDragLayer.clearAllResizeFrames();
1663 updateRunning();
1664
1665 // Reset AllApps to its initial state only if we are not in the middle of
1666 // processing a multi-step drop
1667 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) {
1668 showWorkspace(false);
1669 }
1670 } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
1671 mUserPresent = true;
1672 updateRunning();
1673 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.DELETE_DATABASE.equals(action)) {
1674 mModel.resetLoadedState(false, true);
1675 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1676 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE);
1677 } else if (ENABLE_DEBUG_INTENTS && DebugIntents.MIGRATE_DATABASE.equals(action)) {
1678 mModel.resetLoadedState(false, true);
1679 mModel.startLoader(false, PagedView.INVALID_RESTORE_PAGE,
1680 LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
1681 | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
1682
1683 <<<<<<< LEFT
1684 } else if (LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED.equals(action)
1685 || LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
1686 getModel().forceReload();
1687
1688 ||||||| BASE
1689 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
1690 =======
1691
1692
1693 >>>>>>> RIGHT
1694 }
1695 }
1696 };
1697
1698 @Override
1699 public void onAttachedToWindow() {
1700 super.onAttachedToWindow();
1701
1702 // Listen for broadcasts related to user-presence
1703 final IntentFilter filter = new IntentFilter();
1704 filter.addAction(Intent.ACTION_SCREEN_OFF);
1705 filter.addAction(Intent.ACTION_USER_PRESENT);
1706
1707 <<<<<<< LEFT
1708 // For handling managed profiles
1709 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
1710 filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
1711
1712 ||||||| BASE
1713 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
1714 =======
1715
1716
1717 >>>>>>> RIGHT
1718 if (ENABLE_DEBUG_INTENTS) {
1719 filter.addAction(DebugIntents.DELETE_DATABASE);
1720 filter.addAction(DebugIntents.MIGRATE_DATABASE);
1721 }
1722 registerReceiver(mReceiver, filter);
1723 FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
1724 setupTransparentSystemBarsForLmp();
1725 mAttached = true;
1726 mVisible = true;
1727 }
1728
1729 /**
1730 * Sets up transparent navigation and status bars in LMP.
1731 * This method is a no-op for other platform versions.
1732 */
1733 @TargetApi(19)
1734 private void setupTransparentSystemBarsForLmp() {
1735 // TODO(sansid): use the APIs directly when compiling against L sdk.
1736 // Currently we use reflection to access the flags and the API to set the transparency
1737 // on the System bars.
1738 if (Utilities.isLmpOrAbove()) {
1739 try {
1740 getWindow().getAttributes().systemUiVisibility |=
1741 (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1742 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1743 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
1744 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
1745 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
1746 Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
1747 "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
1748 getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
1749
1750 Method setStatusBarColorMethod =
1751 Window.class.getDeclaredMethod("setStatusBarColor", int.class);
1752 Method setNavigationBarColorMethod =
1753 Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
1754 setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1755 setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
1756 } catch (NoSuchFieldException e) {
1757 Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
1758 } catch (NoSuchMethodException ex) {
1759 Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
1760 } catch (IllegalAccessException e) {
1761 Log.w(TAG, "IllegalAccessException while setting up transparent bars");
1762 } catch (IllegalArgumentException e) {
1763 Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
1764 } catch (InvocationTargetException e) {
1765 Log.w(TAG, "InvocationTargetException while setting up transparent bars");
1766 } finally {}
1767 }
1768 }
1769
1770 @Override
1771 public void onDetachedFromWindow() {
1772 super.onDetachedFromWindow();
1773 mVisible = false;
1774
1775 if (mAttached) {
1776 unregisterReceiver(mReceiver);
1777 mAttached = false;
1778 }
1779 updateRunning();
1780 }
1781
1782 public void onWindowVisibilityChanged(int visibility) {
1783 mVisible = visibility == View.VISIBLE;
1784 updateRunning();
1785 // The following code used to be in onResume, but it turns out onResume is called when
1786 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged
1787 // is a more appropriate event to handle
1788 if (mVisible) {
1789 mAppsCustomizeTabHost.onWindowVisible();
1790 if (!mWorkspaceLoading) {
1791 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver();
1792 // We want to let Launcher draw itself at least once before we force it to build
1793 // layers on all the workspace pages, so that transitioning to Launcher from other
1794 // apps is nice and speedy.
1795 observer.addOnDrawListener(new ViewTreeObserver.OnDrawListener() {
1796 private boolean mStarted = false;
1797 public void onDraw() {
1798 if (mStarted) return;
1799 mStarted = true;
1800 // We delay the layer building a bit in order to give
1801 // other message processing a time to run. In particular
1802 // this avoids a delay in hiding the IME if it was
1803 // currently shown, because doing that may involve
1804 // some communication back with the app.
1805 mWorkspace.postDelayed(mBuildLayersRunnable, 500);
1806 final ViewTreeObserver.OnDrawListener listener = this;
1807 mWorkspace.post(new Runnable() {
1808 public void run() {
1809 if (mWorkspace != null &&
1810 mWorkspace.getViewTreeObserver() != null) {
1811 mWorkspace.getViewTreeObserver().
1812 removeOnDrawListener(listener);
1813 }
1814 }
1815 });
1816 return;
1817 }
1818 });
1819 }
1820 clearTypedText();
1821 }
1822 }
1823
1824 private void sendAdvanceMessage(long delay) {
1825 mHandler.removeMessages(ADVANCE_MSG);
1826 Message msg = mHandler.obtainMessage(ADVANCE_MSG);
1827 mHandler.sendMessageDelayed(msg, delay);
1828 mAutoAdvanceSentTime = System.currentTimeMillis();
1829 }
1830
1831 private void updateRunning() {
1832 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty();
1833 if (autoAdvanceRunning != mAutoAdvanceRunning) {
1834 mAutoAdvanceRunning = autoAdvanceRunning;
1835 if (autoAdvanceRunning) {
1836 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft;
1837 sendAdvanceMessage(delay);
1838 } else {
1839 if (!mWidgetsToAdvance.isEmpty()) {
1840 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval -
1841 (System.currentTimeMillis() - mAutoAdvanceSentTime));
1842 }
1843 mHandler.removeMessages(ADVANCE_MSG);
1844 mHandler.removeMessages(0); // Remove messages sent using postDelayed()
1845 }
1846 }
1847 }
1848
1849 private final Handler mHandler = new Handler() {
1850 @Override
1851 public void handleMessage(Message msg) {
1852 if (msg.what == ADVANCE_MSG) {
1853 int i = 0;
1854 for (View key: mWidgetsToAdvance.keySet()) {
1855 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId);
1856 final int delay = mAdvanceStagger * i;
1857 if (v instanceof Advanceable) {
1858 postDelayed(new Runnable() {
1859 public void run() {
1860 ((Advanceable) v).advance();
1861 }
1862 }, delay);
1863 }
1864 i++;
1865 }
1866 sendAdvanceMessage(mAdvanceInterval);
1867 }
1868 }
1869 };
1870
1871 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) {
1872 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return;
1873 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId);
1874 if (v instanceof Advanceable) {
1875 mWidgetsToAdvance.put(hostView, appWidgetInfo);
1876 ((Advanceable) v).fyiWillBeAdvancedByHostKThx();
1877 updateRunning();
1878 }
1879 }
1880
1881 void removeWidgetToAutoAdvance(View hostView) {
1882 if (mWidgetsToAdvance.containsKey(hostView)) {
1883 mWidgetsToAdvance.remove(hostView);
1884 updateRunning();
1885 }
1886 }
1887
1888 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
1889 removeWidgetToAutoAdvance(launcherInfo.hostView);
1890 launcherInfo.hostView = null;
1891 }
1892
1893 void showOutOfSpaceMessage(boolean isHotseatLayout) {
1894 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space);
1895 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show();
1896 }
1897
1898 public DragLayer getDragLayer() {
1899 return mDragLayer;
1900 }
1901
1902 public Workspace getWorkspace() {
1903 return mWorkspace;
1904 }
1905
1906 public Hotseat getHotseat() {
1907 return mHotseat;
1908 }
1909
1910
1911 <<<<<<< LEFT
1912 public ViewGroup getOverviewPanel() {
1913
1914 ||||||| BASE
1915 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
1916 =======
1917
1918 public View getOverviewPanel() {
1919
1920 >>>>>>> RIGHT
1921 return mOverviewPanel;
1922 }
1923
1924 public SearchDropTargetBar getSearchBar() {
1925 return mSearchDropTargetBar;
1926 }
1927
1928 public LauncherAppWidgetHost getAppWidgetHost() {
1929 return mAppWidgetHost;
1930 }
1931
1932 public LauncherModel getModel() {
1933 return mModel;
1934 }
1935
1936
1937 <<<<<<< LEFT
1938
1939 ||||||| BASE
1940 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
1941 =======
1942
1943 public LauncherClings getLauncherClings() {
1944 return mLauncherClings;
1945 }
1946
1947
1948 >>>>>>> RIGHT
1949 protected SharedPreferences getSharedPrefs() {
1950 return mSharedPrefs;
1951 }
1952
1953 public void closeSystemDialogs() {
1954 getWindow().closeAllPanels();
1955
1956 // Whatever we were doing is hereby canceled.
1957 setWaitingForResult(false);
1958 }
1959
1960 @Override
1961 protected void onNewIntent(Intent intent) {
1962 long startTime = 0;
1963 if (DEBUG_RESUME_TIME) {
1964 startTime = System.currentTimeMillis();
1965 }
1966 super.onNewIntent(intent);
1967
1968 // Close the menu
1969 if (Intent.ACTION_MAIN.equals(intent.getAction())) {
1970 // also will cancel mWaitingForResult.
1971 closeSystemDialogs();
1972
1973 final boolean alreadyOnHome = mHasFocus && ((intent.getFlags() &
1974 Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
1975 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
1976
1977 if (mWorkspace == null) {
1978 // Can be cases where mWorkspace is null, this prevents a NPE
1979 return;
1980 }
1981 Folder openFolder = mWorkspace.getOpenFolder();
1982 // In all these cases, only animate if we're already on home
1983 mWorkspace.exitWidgetResizeMode();
1984 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
1985 openFolder == null && shouldMoveToDefaultScreenOnHomeIntent()) {
1986 mWorkspace.moveToDefaultScreen(true);
1987 }
1988
1989 closeFolder();
1990 exitSpringLoadedDragMode();
1991
1992 // If we are already on home, then just animate back to the workspace,
1993 // otherwise, just wait until onResume to set the state back to Workspace
1994 if (alreadyOnHome) {
1995 showWorkspace(true);
1996 } else {
1997 mOnResumeState = State.WORKSPACE;
1998 }
1999
2000 final View v = getWindow().peekDecorView();
2001 if (v != null && v.getWindowToken() != null) {
2002 InputMethodManager imm = (InputMethodManager)getSystemService(
2003 INPUT_METHOD_SERVICE);
2004 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
2005 }
2006
2007 // Reset the apps customize page
2008 if (!alreadyOnHome && mAppsCustomizeTabHost != null) {
2009 mAppsCustomizeTabHost.reset();
2010 }
2011
2012 onHomeIntent();
2013 }
2014
2015 if (DEBUG_RESUME_TIME) {
2016 Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
2017 }
2018 }
2019
2020 /**
2021 * Override point for subclasses to prevent movement to the default screen when the home
2022 * button is pressed. Used (for example) in GEL, to prevent movement during a search.
2023 */
2024 protected boolean shouldMoveToDefaultScreenOnHomeIntent() {
2025 return true;
2026 }
2027
2028 /**
2029 * Override point for subclasses to provide custom behaviour for when a home intent is fired.
2030 */
2031 protected void onHomeIntent() {
2032 // Do nothing
2033 }
2034
2035 @Override
2036 public void onRestoreInstanceState(Bundle state) {
2037 super.onRestoreInstanceState(state);
2038 for (int page: mSynchronouslyBoundPages) {
2039 mWorkspace.restoreInstanceStateForChild(page);
2040 }
2041 }
2042
2043 @Override
2044 protected void onSaveInstanceState(Bundle outState) {
2045 if (mWorkspace.getChildCount() > 0) {
2046 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN,
2047 mWorkspace.getCurrentPageOffsetFromCustomContent());
2048 }
2049 super.onSaveInstanceState(outState);
2050
2051 outState.putInt(RUNTIME_STATE, mState.ordinal());
2052 // We close any open folder since it will not be re-opened, and we need to make sure
2053 // this state is reflected.
2054 closeFolder();
2055
2056 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 &&
2057 mWaitingForResult) {
2058 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
2059 outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
2060 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
2061 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
2062 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
2063 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
2064 outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
2065 outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
2066 }
2067
2068 if (mFolderInfo != null && mWaitingForResult) {
2069 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
2070 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
2071 }
2072
2073 // Save the current AppsCustomize tab
2074 if (mAppsCustomizeTabHost != null) {
2075 AppsCustomizePagedView.ContentType type = mAppsCustomizeContent.getContentType();
2076 String currentTabTag = mAppsCustomizeTabHost.getTabTagForContentType(type);
2077 if (currentTabTag != null) {
2078 outState.putString("apps_customize_currentTab", currentTabTag);
2079 }
2080 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex();
2081 outState.putInt("apps_customize_currentIndex", currentIndex);
2082 }
2083 outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);
2084 }
2085
2086 @Override
2087 public void onDestroy() {
2088 super.onDestroy();
2089
2090 // Remove all pending runnables
2091 mHandler.removeMessages(ADVANCE_MSG);
2092 mHandler.removeMessages(0);
2093 mWorkspace.removeCallbacks(mBuildLayersRunnable);
2094
2095 // Stop callbacks from LauncherModel
2096 LauncherAppState app = (LauncherAppState.getInstance());
2097
2098 // It's possible to receive onDestroy after a new Launcher activity has
2099 // been created. In this case, don't interfere with the new Launcher.
2100 if (mModel.isCurrentCallbacks(this)) {
2101 mModel.stopLoader();
2102 app.setLauncher(null);
2103 }
2104
2105 try {
2106 mAppWidgetHost.stopListening();
2107 } catch (NullPointerException ex) {
2108 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
2109 }
2110 mAppWidgetHost = null;
2111
2112 mWidgetsToAdvance.clear();
2113
2114 TextKeyListener.getInstance().release();
2115
2116 // Disconnect any of the callbacks and drawables associated with ItemInfos on the workspace
2117 // to prevent leaking Launcher activities on orientation change.
2118 if (mModel != null) {
2119 mModel.unbindItemInfosAndClearQueuedBindRunnables();
2120 }
2121
2122 getContentResolver().unregisterContentObserver(mWidgetObserver);
2123 unregisterReceiver(mCloseSystemDialogsReceiver);
2124
2125 mDragLayer.clearAllResizeFrames();
2126 ((ViewGroup) mWorkspace.getParent()).removeAllViews();
2127 mWorkspace.removeAllWorkspaceScreens();
2128 mWorkspace = null;
2129 mDragController = null;
2130
2131 PackageInstallerCompat.getInstance(this).onStop();
2132 LauncherAnimUtils.onDestroyActivity();
2133 }
2134
2135 public DragController getDragController() {
2136 return mDragController;
2137 }
2138
2139 @Override
2140 public void startActivityForResult(Intent intent, int requestCode) {
2141 if (requestCode >= 0) {
2142 setWaitingForResult(true);
2143 }
2144 super.startActivityForResult(intent, requestCode);
2145 }
2146
2147 /**
2148 * Indicates that we want global search for this activity by setting the globalSearch
2149 * argument for {@link #startSearch} to true.
2150 */
2151 @Override
2152 public void startSearch(String initialQuery, boolean selectInitialQuery,
2153 Bundle appSearchData, boolean globalSearch) {
2154
2155 showWorkspace(true);
2156
2157 if (initialQuery == null) {
2158 // Use any text typed in the launcher as the initial query
2159 initialQuery = getTypedText();
2160 }
2161 if (appSearchData == null) {
2162 appSearchData = new Bundle();
2163 appSearchData.putString("source", "launcher-search");
2164 }
2165 Rect sourceBounds = new Rect();
2166 if (mSearchDropTargetBar != null) {
2167 sourceBounds = mSearchDropTargetBar.getSearchBarBounds();
2168 }
2169
2170 boolean clearTextImmediately = startSearch(initialQuery, selectInitialQuery,
2171 appSearchData, sourceBounds);
2172 if (clearTextImmediately) {
2173 clearTypedText();
2174 }
2175 }
2176
2177 /**
2178 * Start a text search.
2179 *
2180 * @return {@code true} if the search will start immediately, so any further keypresses
2181 * will be handled directly by the search UI. {@code false} if {@link Launcher} should continue
2182 * to buffer keypresses.
2183 */
2184 public boolean startSearch(String initialQuery,
2185 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2186 startGlobalSearch(initialQuery, selectInitialQuery,
2187 appSearchData, sourceBounds);
2188 return false;
2189 }
2190
2191 /**
2192 * Starts the global search activity. This code is a copied from SearchManager
2193 */
2194 private void startGlobalSearch(String initialQuery,
2195 boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
2196 final SearchManager searchManager =
2197 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2198 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
2199 if (globalSearchActivity == null) {
2200 Log.w(TAG, "No global search activity found.");
2201 return;
2202 }
2203 Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
2204 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2205 intent.setComponent(globalSearchActivity);
2206 // Make sure that we have a Bundle to put source in
2207 if (appSearchData == null) {
2208 appSearchData = new Bundle();
2209 } else {
2210 appSearchData = new Bundle(appSearchData);
2211 }
2212 // Set source to package name of app that starts global search, if not set already.
2213 if (!appSearchData.containsKey("source")) {
2214 appSearchData.putString("source", getPackageName());
2215 }
2216 intent.putExtra(SearchManager.APP_DATA, appSearchData);
2217 if (!TextUtils.isEmpty(initialQuery)) {
2218 intent.putExtra(SearchManager.QUERY, initialQuery);
2219 }
2220 if (selectInitialQuery) {
2221 intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
2222 }
2223 intent.setSourceBounds(sourceBounds);
2224 try {
2225 startActivity(intent);
2226 } catch (ActivityNotFoundException ex) {
2227 Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
2228 }
2229 }
2230
2231 public boolean isOnCustomContent() {
2232 return mWorkspace.isOnOrMovingToCustomContent();
2233 }
2234
2235 @Override
2236 public boolean onPrepareOptionsMenu(Menu menu) {
2237 super.onPrepareOptionsMenu(menu);
2238 if (!isOnCustomContent()) {
2239 // Close any open folders
2240 closeFolder();
2241 // Stop resizing any widgets
2242 mWorkspace.exitWidgetResizeMode();
2243 if (!mWorkspace.isInOverviewMode()) {
2244 // Show the overview mode
2245 showOverviewMode(true);
2246 } else {
2247 showWorkspace(true);
2248 }
2249 }
2250 return false;
2251 }
2252
2253 @Override
2254 public boolean onSearchRequested() {
2255 startSearch(null, false, null, true);
2256 // Use a custom animation for launching search
2257 return true;
2258 }
2259
2260 public boolean isWorkspaceLocked() {
2261 return mWorkspaceLoading || mWaitingForResult;
2262 }
2263
2264 public boolean isWorkspaceLoading() {
2265 return mWorkspaceLoading;
2266 }
2267
2268 private void setWorkspaceLoading(boolean value) {
2269 boolean isLocked = isWorkspaceLocked();
2270 mWorkspaceLoading = value;
2271 if (isLocked != isWorkspaceLocked()) {
2272 onWorkspaceLockedChanged();
2273 }
2274 }
2275
2276 private void setWaitingForResult(boolean value) {
2277 boolean isLocked = isWorkspaceLocked();
2278 mWaitingForResult = value;
2279 if (isLocked != isWorkspaceLocked()) {
2280 onWorkspaceLockedChanged();
2281 }
2282 }
2283
2284 protected void onWorkspaceLockedChanged() { }
2285
2286 private void resetAddInfo() {
2287 mPendingAddInfo.container = ItemInfo.NO_ID;
2288 mPendingAddInfo.screenId = -1;
2289 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1;
2290 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1;
2291 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1;
2292 mPendingAddInfo.dropPos = null;
2293 }
2294
2295 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2296 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo) {
2297 addAppWidgetImpl(appWidgetId, info, boundWidget, appWidgetInfo, 0);
2298 }
2299
2300 void addAppWidgetImpl(final int appWidgetId, final ItemInfo info,
2301 final AppWidgetHostView boundWidget, final AppWidgetProviderInfo appWidgetInfo, int
2302 delay) {
2303 if (appWidgetInfo.configure != null) {
2304 mPendingAddWidgetInfo = appWidgetInfo;
2305 mPendingAddWidgetId = appWidgetId;
2306
2307 // Launch over to configure widget, if needed
2308 mAppWidgetManager.startConfigActivity(appWidgetInfo, appWidgetId, this,
2309 mAppWidgetHost, REQUEST_CREATE_APPWIDGET);
2310
2311 } else {
2312 // Otherwise just add it
2313 Runnable onComplete = new Runnable() {
2314 @Override
2315 public void run() {
2316 // Exit spring loaded mode if necessary after adding the widget
2317 exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT,
2318 null);
2319 }
2320 };
2321 completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget,
2322 appWidgetInfo);
2323 mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false);
2324 }
2325 }
2326
2327 protected void moveToCustomContentScreen(boolean animate) {
2328 // Close any folders that may be open.
2329 closeFolder();
2330 mWorkspace.moveToCustomContentScreen(animate);
2331 }
2332 /**
2333 * Process a shortcut drop.
2334 *
2335 * @param componentName The name of the component
2336 * @param screenId The ID of the screen where it should be added
2337 * @param cell The cell it should be added to, optional
2338 * @param position The location on the screen where it was dropped, optional
2339 */
2340 void processShortcutFromDrop(ComponentName componentName, long container, long screenId,
2341 int[] cell, int[] loc) {
2342 resetAddInfo();
2343 mPendingAddInfo.container = container;
2344 mPendingAddInfo.screenId = screenId;
2345 mPendingAddInfo.dropPos = loc;
2346
2347 if (cell != null) {
2348 mPendingAddInfo.cellX = cell[0];
2349 mPendingAddInfo.cellY = cell[1];
2350 }
2351
2352 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
2353 createShortcutIntent.setComponent(componentName);
2354 processShortcut(createShortcutIntent);
2355 }
2356
2357 /**
2358 * Process a widget drop.
2359 *
2360 * @param info The PendingAppWidgetInfo of the widget being added.
2361 * @param screenId The ID of the screen where it should be added
2362 * @param cell The cell it should be added to, optional
2363 * @param position The location on the screen where it was dropped, optional
2364 */
2365 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId,
2366 int[] cell, int[] span, int[] loc) {
2367 resetAddInfo();
2368 mPendingAddInfo.container = info.container = container;
2369 mPendingAddInfo.screenId = info.screenId = screenId;
2370 mPendingAddInfo.dropPos = loc;
2371 mPendingAddInfo.minSpanX = info.minSpanX;
2372 mPendingAddInfo.minSpanY = info.minSpanY;
2373
2374 if (cell != null) {
2375 mPendingAddInfo.cellX = cell[0];
2376 mPendingAddInfo.cellY = cell[1];
2377 }
2378 if (span != null) {
2379 mPendingAddInfo.spanX = span[0];
2380 mPendingAddInfo.spanY = span[1];
2381 }
2382
2383 AppWidgetHostView hostView = info.boundWidget;
2384 int appWidgetId;
2385 if (hostView != null) {
2386 appWidgetId = hostView.getAppWidgetId();
2387 addAppWidgetImpl(appWidgetId, info, hostView, info.info);
2388 } else {
2389 // In this case, we either need to start an activity to get permission to bind
2390 // the widget, or we need to start an activity to configure the widget, or both.
2391 appWidgetId = getAppWidgetHost().allocateAppWidgetId();
2392 Bundle options = info.bindOptions;
2393
2394 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
2395 appWidgetId, info.info, options);
2396 if (success) {
2397 addAppWidgetImpl(appWidgetId, info, null, info.info);
2398 } else {
2399 mPendingAddWidgetInfo = info.info;
2400 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
2401 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
2402 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
2403 mAppWidgetManager.getUser(mPendingAddWidgetInfo)
2404 .addToIntent(intent, AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
2405 // TODO: we need to make sure that this accounts for the options bundle.
2406 // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
2407 startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
2408 }
2409 }
2410 }
2411
2412 void processShortcut(Intent intent) {
2413 Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_SHORTCUT);
2414 }
2415
2416 void processWallpaper(Intent intent) {
2417 startActivityForResult(intent, REQUEST_PICK_WALLPAPER);
2418 }
2419
2420 FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
2421 int cellY) {
2422 final FolderInfo folderInfo = new FolderInfo();
2423 folderInfo.title = getText(R.string.folder_name);
2424
2425 // Update the model
2426 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
2427 false);
2428 sFolders.put(folderInfo.id, folderInfo);
2429
2430 // Create the view
2431 FolderIcon newFolder =
2432 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache);
2433 mWorkspace.addInScreen(newFolder, container, screenId, cellX, cellY, 1, 1,
2434 isWorkspaceLocked());
2435 // Force measure the new folder icon
2436 CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder);
2437 parent.getShortcutsAndWidgets().measureChild(newFolder);
2438 return newFolder;
2439 }
2440
2441 void removeFolder(FolderInfo folder) {
2442 sFolders.remove(folder.id);
2443 }
2444
2445 protected ComponentName getWallpaperPickerComponent() {
2446 return new ComponentName(getPackageName(), LauncherWallpaperPickerActivity.class.getName());
2447 }
2448
2449 /**
2450 * Registers various content observers. The current implementation registers
2451 * only a favorites observer to keep track of the favorites applications.
2452 */
2453 private void registerContentObservers() {
2454 ContentResolver resolver = getContentResolver();
2455 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
2456 true, mWidgetObserver);
2457 }
2458
2459 @Override
2460 public boolean dispatchKeyEvent(KeyEvent event) {
2461 if (event.getAction() == KeyEvent.ACTION_DOWN) {
2462 switch (event.getKeyCode()) {
2463 case KeyEvent.KEYCODE_HOME:
2464 return true;
2465 case KeyEvent.KEYCODE_VOLUME_DOWN:
2466 if (isPropertyEnabled(DUMP_STATE_PROPERTY)) {
2467 dumpState();
2468 return true;
2469 }
2470 break;
2471 }
2472 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2473 switch (event.getKeyCode()) {
2474 case KeyEvent.KEYCODE_HOME:
2475 return true;
2476 }
2477 }
2478
2479 return super.dispatchKeyEvent(event);
2480 }
2481
2482 @Override
2483 public void onBackPressed() {
2484 if (isAllAppsVisible()) {
2485 if (mAppsCustomizeContent.getContentType() ==
2486 AppsCustomizePagedView.ContentType.Applications) {
2487 showWorkspace(true);
2488 } else {
2489 showOverviewMode(true);
2490 }
2491 } else if (mWorkspace.isInOverviewMode()) {
2492 mWorkspace.exitOverviewMode(true);
2493 } else if (mWorkspace.getOpenFolder() != null) {
2494 Folder openFolder = mWorkspace.getOpenFolder();
2495 if (openFolder.isEditingName()) {
2496 openFolder.dismissEditingName();
2497 } else {
2498 closeFolder();
2499 }
2500 } else {
2501 mWorkspace.exitWidgetResizeMode();
2502
2503 // Back button is a no-op here, but give at least some feedback for the button press
2504 mWorkspace.showOutlinesTemporarily();
2505 }
2506 }
2507
2508 /**
2509 * Re-listen when widgets are reset.
2510 */
2511 private void onAppWidgetReset() {
2512 if (mAppWidgetHost != null) {
2513 mAppWidgetHost.startListening();
2514 }
2515 }
2516
2517 /**
2518 * Launches the intent referred by the clicked shortcut.
2519 *
2520 * @param v The view representing the clicked shortcut.
2521 */
2522 public void onClick(View v) {
2523 // Make sure that rogue clicks don't get through while allapps is launching, or after the
2524 // view has detached (it's possible for this to happen if the view is removed mid touch).
2525 if (v.getWindowToken() == null) {
2526 return;
2527 }
2528
2529 if (!mWorkspace.isFinishedSwitchingState()) {
2530 return;
2531 }
2532
2533 if (v instanceof Workspace) {
2534 if (mWorkspace.isInOverviewMode()) {
2535 mWorkspace.exitOverviewMode(true);
2536 }
2537 return;
2538 }
2539
2540 if (v instanceof CellLayout) {
2541 if (mWorkspace.isInOverviewMode()) {
2542 mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true);
2543 }
2544 }
2545
2546 Object tag = v.getTag();
2547 if (tag instanceof ShortcutInfo) {
2548 onClickAppShortcut(v);
2549 } else if (tag instanceof FolderInfo) {
2550 if (v instanceof FolderIcon) {
2551 onClickFolderIcon(v);
2552 }
2553 } else if (v == mAllAppsButton) {
2554 onClickAllAppsButton(v);
2555 } else if (tag instanceof AppInfo) {
2556 startAppShortcutOrInfoActivity(v);
2557 } else if (tag instanceof LauncherAppWidgetInfo) {
2558 if (v instanceof PendingAppWidgetHostView) {
2559 onClickPendingWidget((PendingAppWidgetHostView) v);
2560 }
2561 }
2562 }
2563
2564 public void onClickPagedViewIcon(View v) {
2565 startAppShortcutOrInfoActivity(v);
2566 }
2567
2568 public boolean onTouch(View v, MotionEvent event) {
2569 return false;
2570 }
2571
2572 /**
2573 * Event handler for the app widget view which has not fully restored.
2574 */
2575 public void onClickPendingWidget(final PendingAppWidgetHostView v) {
2576 final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
2577 if (v.isReadyForClickSetup()) {
2578 int widgetId = info.appWidgetId;
2579 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
2580 if (appWidgetInfo != null) {
2581 mPendingAddWidgetInfo = appWidgetInfo;
2582 mPendingAddInfo.copyFrom(info);
2583 mPendingAddWidgetId = widgetId;
2584
2585 AppWidgetManagerCompat.getInstance(this).startConfigActivity(appWidgetInfo,
2586 info.appWidgetId, this, mAppWidgetHost, REQUEST_RECONFIGURE_APPWIDGET);
2587 }
2588 } else if (info.installProgress < 0) {
2589 // The install has not been queued
2590 final String packageName = info.providerName.getPackageName();
2591 showBrokenAppInstallDialog(packageName,
2592 new DialogInterface.OnClickListener() {
2593 public void onClick(DialogInterface dialog, int id) {
2594 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2595 }
2596 });
2597 } else {
2598 // Download has started.
2599 final String packageName = info.providerName.getPackageName();
2600 startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
2601 }
2602 }
2603
2604 /**
2605 * Event handler for the search button
2606 *
2607 * @param v The view that was clicked.
2608 */
2609 public void onClickSearchButton(View v) {
2610 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2611
2612 onSearchRequested();
2613 }
2614
2615 /**
2616 * Event handler for the voice button
2617 *
2618 * @param v The view that was clicked.
2619 */
2620 public void onClickVoiceButton(View v) {
2621 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2622
2623 startVoice();
2624 }
2625
2626 public void startVoice() {
2627 try {
2628 final SearchManager searchManager =
2629 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
2630 ComponentName activityName = searchManager.getGlobalSearchActivity();
2631 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2632 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2633 if (activityName != null) {
2634 intent.setPackage(activityName.getPackageName());
2635 }
2636 startActivity(null, intent, "onClickVoiceButton");
2637 } catch (ActivityNotFoundException e) {
2638 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2639 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2640 startActivitySafely(null, intent, "onClickVoiceButton");
2641 }
2642 }
2643
2644 /**
2645 * Event handler for the "grid" button that appears on the home screen, which
2646 * enters all apps mode.
2647 *
2648 * @param v The view that was clicked.
2649 */
2650 protected void onClickAllAppsButton(View v) {
2651 if (LOGD) Log.d(TAG, "onClickAllAppsButton");
2652 if (isAllAppsVisible()) {
2653 showWorkspace(true);
2654 } else {
2655 showAllApps(true, AppsCustomizePagedView.ContentType.Applications, false);
2656 }
2657 }
2658
2659 private void showBrokenAppInstallDialog(final String packageName,
2660 DialogInterface.OnClickListener onSearchClickListener) {
2661 new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault))
2662 .setTitle(R.string.abandoned_promises_title)
2663 .setMessage(R.string.abandoned_promise_explanation)
2664 .setPositiveButton(R.string.abandoned_search, onSearchClickListener)
2665 .setNeutralButton(R.string.abandoned_clean_this,
2666 new DialogInterface.OnClickListener() {
2667 public void onClick(DialogInterface dialog, int id) {
2668 final UserHandleCompat user = UserHandleCompat.myUserHandle();
2669 mWorkspace.removeAbandonedPromise(packageName, user);
2670 }
2671 })
2672 .create().show();
2673 return;
2674 }
2675
2676 /**
2677 * Event handler for an app shortcut click.
2678 *
2679 * @param v The view that was clicked. Must be a tagged with a {@link ShortcutInfo}.
2680 */
2681 protected void onClickAppShortcut(final View v) {
2682 if (LOGD) Log.d(TAG, "onClickAppShortcut");
2683 Object tag = v.getTag();
2684 if (!(tag instanceof ShortcutInfo)) {
2685 throw new IllegalArgumentException("Input must be a Shortcut");
2686 }
2687
2688 // Open shortcut
2689 final ShortcutInfo shortcut = (ShortcutInfo) tag;
2690 final Intent intent = shortcut.intent;
2691
2692 // Check for special shortcuts
2693 if (intent.getComponent() != null) {
2694 final String shortcutClass = intent.getComponent().getClassName();
2695
2696 if (shortcutClass.equals(MemoryDumpActivity.class.getName())) {
2697 MemoryDumpActivity.startDump(this);
2698 return;
2699 } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) {
2700 toggleShowWeightWatcher();
2701 return;
2702 }
2703 }
2704
2705 // Check for abandoned promise
2706 if ((v instanceof BubbleTextView)
2707 && shortcut.isPromise()
2708 && !shortcut.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE)) {
2709 showBrokenAppInstallDialog(
2710 shortcut.getTargetComponent().getPackageName(),
2711 new DialogInterface.OnClickListener() {
2712 public void onClick(DialogInterface dialog, int id) {
2713 startAppShortcutOrInfoActivity(v);
2714 }
2715 });
2716 return;
2717 }
2718
2719 // Start activities
2720 startAppShortcutOrInfoActivity(v);
2721 }
2722
2723 private void startAppShortcutOrInfoActivity(View v) {
2724 Object tag = v.getTag();
2725 final ShortcutInfo shortcut;
2726 final Intent intent;
2727 if (tag instanceof ShortcutInfo) {
2728 shortcut = (ShortcutInfo) tag;
2729 intent = shortcut.intent;
2730 int[] pos = new int[2];
2731 v.getLocationOnScreen(pos);
2732 intent.setSourceBounds(new Rect(pos[0], pos[1],
2733 pos[0] + v.getWidth(), pos[1] + v.getHeight()));
2734
2735 } else if (tag instanceof AppInfo) {
2736 shortcut = null;
2737 intent = ((AppInfo) tag).intent;
2738 } else {
2739 throw new IllegalArgumentException("Input must be a Shortcut or AppInfo");
2740 }
2741
2742 boolean success = startActivitySafely(v, intent, tag);
2743 mStats.recordLaunch(intent, shortcut);
2744
2745 if (success && v instanceof BubbleTextView) {
2746 mWaitingForResume = (BubbleTextView) v;
2747 mWaitingForResume.setStayPressed(true);
2748 }
2749 }
2750
2751 /**
2752 * Event handler for a folder icon click.
2753 *
2754 * @param v The view that was clicked. Must be an instance of {@link FolderIcon}.
2755 */
2756 protected void onClickFolderIcon(View v) {
2757 if (LOGD) Log.d(TAG, "onClickFolder");
2758 if (!(v instanceof FolderIcon)){
2759 throw new IllegalArgumentException("Input must be a FolderIcon");
2760 }
2761
2762 FolderIcon folderIcon = (FolderIcon) v;
2763 final FolderInfo info = folderIcon.getFolderInfo();
2764 Folder openFolder = mWorkspace.getFolderForTag(info);
2765
2766 // If the folder info reports that the associated folder is open, then verify that
2767 // it is actually opened. There have been a few instances where this gets out of sync.
2768 if (info.opened && openFolder == null) {
2769 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: "
2770 + info.screenId + " (" + info.cellX + ", " + info.cellY + ")");
2771 info.opened = false;
2772 }
2773
2774 if (!info.opened && !folderIcon.getFolder().isDestroyed()) {
2775 // Close any open folder
2776 closeFolder();
2777 // Open the requested folder
2778 openFolder(folderIcon);
2779 } else {
2780 // Find the open folder...
2781 int folderScreen;
2782 if (openFolder != null) {
2783 folderScreen = mWorkspace.getPageForView(openFolder);
2784 // .. and close it
2785 closeFolder(openFolder);
2786 if (folderScreen != mWorkspace.getCurrentPage()) {
2787 // Close any folder open on the current screen
2788 closeFolder();
2789 // Pull the folder onto this screen
2790 openFolder(folderIcon);
2791 }
2792 }
2793 }
2794 }
2795
2796 /**
2797 * Event handler for the (Add) Widgets button that appears after a long press
2798 * on the home screen.
2799 */
2800 protected void onClickAddWidgetButton(View view) {
2801 if (LOGD) Log.d(TAG, "onClickAddWidgetButton");
2802 showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true);
2803 }
2804
2805 /**
2806 * Event handler for the wallpaper picker button that appears after a long press
2807 * on the home screen.
2808 */
2809 protected void onClickWallpaperPicker(View v) {
2810 if (LOGD) Log.d(TAG, "onClickWallpaperPicker");
2811 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
2812 pickWallpaper.setComponent(getWallpaperPickerComponent());
2813 startActivityForResult(pickWallpaper, REQUEST_PICK_WALLPAPER);
2814 }
2815
2816 /**
2817 * Event handler for a click on the settings button that appears after a long press
2818 * on the home screen.
2819 */
2820 protected void onClickSettingsButton(View v) {
2821 if (LOGD) Log.d(TAG, "onClickSettingsButton");
2822 }
2823
2824 public void onTouchDownAllAppsButton(View v) {
2825 // Provide the same haptic feedback that the system offers for virtual keys.
2826 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2827 }
2828
2829 public void performHapticFeedbackOnTouchDown(View v) {
2830 // Provide the same haptic feedback that the system offers for virtual keys.
2831 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2832 }
2833
2834 public View.OnTouchListener getHapticFeedbackTouchListener() {
2835 if (mHapticFeedbackTouchListener == null) {
2836 mHapticFeedbackTouchListener = new View.OnTouchListener() {
2837 @Override
2838 public boolean onTouch(View v, MotionEvent event) {
2839 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
2840 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
2841 }
2842 return false;
2843 }
2844 };
2845 }
2846 return mHapticFeedbackTouchListener;
2847 }
2848
2849 public void onDragStarted(View view) {}
2850
2851 /**
2852 * Called when the user stops interacting with the launcher.
2853 * This implies that the user is now on the homescreen and is not doing housekeeping.
2854 */
2855 protected void onInteractionEnd() {}
2856
2857 /**
2858 * Called when the user starts interacting with the launcher.
2859 * The possible interactions are:
2860 * - open all apps
2861 * - reorder an app shortcut, or a widget
2862 * - open the overview mode.
2863 * This is a good time to stop doing things that only make sense
2864 * when the user is on the homescreen and not doing housekeeping.
2865 */
2866 protected void onInteractionBegin() {}
2867
2868 void startApplicationDetailsActivity(ComponentName componentName, UserHandleCompat user) {
2869 String packageName = componentName.getPackageName();
2870 try {
2871 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2872 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2873 launcherApps.showAppDetailsForProfile(componentName, user);
2874 } catch (SecurityException e) {
2875 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2876 Log.e(TAG, "Launcher does not have permission to launch settings");
2877 } catch (ActivityNotFoundException e) {
2878 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2879 Log.e(TAG, "Unable to launch settings");
2880 }
2881 }
2882
2883 // returns true if the activity was started
2884 boolean startApplicationUninstallActivity(ComponentName componentName, int flags,
2885 UserHandleCompat user) {
2886 if ((flags & AppInfo.DOWNLOADED_FLAG) == 0) {
2887 // System applications cannot be installed. For now, show a toast explaining that.
2888 // We may give them the option of disabling apps this way.
2889 int messageId = R.string.uninstall_system_app_text;
2890 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();
2891 return false;
2892 } else {
2893 String packageName = componentName.getPackageName();
2894 String className = componentName.getClassName();
2895 Intent intent = new Intent(
2896 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className));
2897 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
2898 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
2899 if (user != null) {
2900 user.addToIntent(intent, Intent.EXTRA_USER);
2901 }
2902 startActivity(intent);
2903 return true;
2904 }
2905 }
2906
2907 boolean startActivity(View v, Intent intent, Object tag) {
2908 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2909 try {
2910 // Only launch using the new animation if the shortcut has not opted out (this is a
2911 // private contract between launcher and may be ignored in the future).
2912 boolean useLaunchAnimation = (v != null) &&
2913 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
2914 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
2915 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
2916
2917 UserHandleCompat user = null;
2918 if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) {
2919 long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1);
2920 user = userManager.getUserForSerialNumber(serialNumber);
2921 }
2922
2923 Bundle optsBundle = null;
2924 if (useLaunchAnimation) {
2925 ActivityOptions opts = Utilities.isLmpOrAbove() ?
2926 ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim)🔵
2927 ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasured🔵
2928 optsBundle = opts.toBundle();
2929 }
2930
2931 if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
2932 // Could be launching some bookkeeping activity
2933 startActivity(intent, optsBundle);
2934 } else {
2935 // TODO Component can be null when shortcuts are supported for secondary user
2936 launcherApps.startActivityForProfile(intent.getComponent(), user,
2937 intent.getSourceBounds(), optsBundle);
2938 }
2939 return true;
2940 } catch (SecurityException e) {
2941 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2942 Log.e(TAG, "Launcher does not have the permission to launch " + intent +
2943 ". Make sure to create a MAIN intent-filter for the corresponding activity " +
2944 "or use the exported attribute for this activity. "
2945 + "tag="+ tag + " intent=" + intent, e);
2946 }
2947 return false;
2948 }
2949
2950 boolean startActivitySafely(View v, Intent intent, Object tag) {
2951 boolean success = false;
2952 if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
2953 Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
2954 return false;
2955 }
2956 try {
2957 success = startActivity(v, intent, tag);
2958 } catch (ActivityNotFoundException e) {
2959 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
2960 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
2961 }
2962 return success;
2963 }
2964
2965 /**
2966 * This method draws the FolderIcon to an ImageView and then adds and positions that ImageView
2967 * in the DragLayer in the exact absolute location of the original FolderIcon.
2968 */
2969 private void copyFolderIconToImage(FolderIcon fi) {
2970 final int width = fi.getMeasuredWidth();
2971 final int height = fi.getMeasuredHeight();
2972
2973 // Lazy load ImageView, Bitmap and Canvas
2974 if (mFolderIconImageView == null) {
2975 mFolderIconImageView = new ImageView(this);
2976 }
2977 if (mFolderIconBitmap == null || mFolderIconBitmap.getWidth() != width ||
2978 mFolderIconBitmap.getHeight() != height) {
2979 mFolderIconBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
2980 mFolderIconCanvas = new Canvas(mFolderIconBitmap);
2981 }
2982
2983 DragLayer.LayoutParams lp;
2984 if (mFolderIconImageView.getLayoutParams() instanceof DragLayer.LayoutParams) {
2985 lp = (DragLayer.LayoutParams) mFolderIconImageView.getLayoutParams();
2986 } else {
2987 lp = new DragLayer.LayoutParams(width, height);
2988 }
2989
2990 // The layout from which the folder is being opened may be scaled, adjust the starting
2991 // view size by this scale factor.
2992 float scale = mDragLayer.getDescendantRectRelativeToSelf(fi, mRectForFolderAnimation);
2993 lp.customPosition = true;
2994 lp.x = mRectForFolderAnimation.left;
2995 lp.y = mRectForFolderAnimation.top;
2996 lp.width = (int) (scale * width);
2997 lp.height = (int) (scale * height);
2998
2999 mFolderIconCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
3000 fi.draw(mFolderIconCanvas);
3001 mFolderIconImageView.setImageBitmap(mFolderIconBitmap);
3002 if (fi.getFolder() != null) {
3003 mFolderIconImageView.setPivotX(fi.getFolder().getPivotXForIconAnimation());
3004 mFolderIconImageView.setPivotY(fi.getFolder().getPivotYForIconAnimation());
3005 }
3006 // Just in case this image view is still in the drag layer from a previous animation,
3007 // we remove it and re-add it.
3008 if (mDragLayer.indexOfChild(mFolderIconImageView) != -1) {
3009 mDragLayer.removeView(mFolderIconImageView);
3010 }
3011 mDragLayer.addView(mFolderIconImageView, lp);
3012 if (fi.getFolder() != null) {
3013 fi.getFolder().bringToFront();
3014 }
3015 }
3016
3017 private void growAndFadeOutFolderIcon(FolderIcon fi) {
3018 if (fi == null) return;
3019 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
3020 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f);
3021 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f);
3022
3023 FolderInfo info = (FolderInfo) fi.getTag();
3024 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3025 CellLayout cl = (CellLayout) fi.getParent().getParent();
3026 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams();
3027 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY);
3028 }
3029
3030 // Push an ImageView copy of the FolderIcon into the DragLayer and hide the original
3031 copyFolderIconToImage(fi);
3032 fi.setVisibility(View.INVISIBLE);
3033
3034 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
3035 scaleX, scaleY);
3036 if (Utilities.isLmpOrAbove()) {
3037 oa.setInterpolator(new LogDecelerateInterpolator(100, 0));
3038 }
3039 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
3040 oa.start();
3041 }
3042
3043 private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
3044 if (fi == null) return;
3045 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
3046 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
3047 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
3048
3049 final CellLayout cl = (CellLayout) fi.getParent().getParent();
3050
3051 // We remove and re-draw the FolderIcon in-case it has changed
3052 mDragLayer.removeView(mFolderIconImageView);
3053 copyFolderIconToImage(fi);
3054 ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(mFolderIconImageView, alpha,
3055 scaleX, scaleY);
3056 oa.setDuration(getResources().getInteger(R.integer.config_folderExpandDuration));
3057 oa.addListener(new AnimatorListenerAdapter() {
3058 @Override
3059 public void onAnimationEnd(Animator animation) {
3060 if (cl != null) {
3061 cl.clearFolderLeaveBehind();
3062 // Remove the ImageView copy of the FolderIcon and make the original visible.
3063 mDragLayer.removeView(mFolderIconImageView);
3064 fi.setVisibility(View.VISIBLE);
3065 }
3066 }
3067 });
3068 oa.start();
3069 }
3070
3071 /**
3072 * Opens the user folder described by the specified tag. The opening of the folder
3073 * is animated relative to the specified View. If the View is null, no animation
3074 * is played.
3075 *
3076 * @param folderInfo The FolderInfo describing the folder to open.
3077 */
3078 public void openFolder(FolderIcon folderIcon) {
3079 Folder folder = folderIcon.getFolder();
3080 FolderInfo info = folder.mInfo;
3081
3082 info.opened = true;
3083
3084 // Just verify that the folder hasn't already been added to the DragLayer.
3085 // There was a one-off crash where the folder had a parent already.
3086 if (folder.getParent() == null) {
3087 mDragLayer.addView(folder);
3088 mDragController.addDropTarget((DropTarget) folder);
3089 } else {
3090 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" +
3091 folder.getParent() + ").");
3092 }
3093 folder.animateOpen();
3094 growAndFadeOutFolderIcon(folderIcon);
3095
3096 // Notify the accessibility manager that this folder "window" has appeared and occluded
3097 // the workspace items
3098 folder.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3099 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
3100 }
3101
3102 public void closeFolder() {
3103 Folder folder = mWorkspace != null ? mWorkspace.getOpenFolder() : null;
3104 if (folder != null) {
3105 if (folder.isEditingName()) {
3106 folder.dismissEditingName();
3107 }
3108 closeFolder(folder);
3109
3110 <<<<<<< LEFT
3111
3112 ||||||| BASE
3113 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
3114 =======
3115
3116
3117 // Dismiss the folder cling
3118 mLauncherClings.dismissFolderCling(null);
3119
3120 >>>>>>> RIGHT
3121 }
3122 }
3123
3124 void closeFolder(Folder folder) {
3125 folder.getInfo().opened = false;
3126
3127 ViewGroup parent = (ViewGroup) folder.getParent().getParent();
3128 if (parent != null) {
3129 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo);
3130 shrinkAndFadeInFolderIcon(fi);
3131 }
3132 folder.animateClosed();
3133
3134 // Notify the accessibility manager that this folder "window" has disappeard and no
3135 // longer occludeds the workspace items
3136 getDragLayer().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3137 }
3138
3139 public boolean onLongClick(View v) {
3140 if (!isDraggingEnabled()) return false;
3141 if (isWorkspaceLocked()) return false;
3142 if (mState != State.WORKSPACE) return false;
3143
3144 if (v instanceof Workspace) {
3145 if (!mWorkspace.isInOverviewMode()) {
3146 if (mWorkspace.enterOverviewMode()) {
3147 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3148 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3149 return true;
3150 } else {
3151 return false;
3152 }
3153 } else {
3154 return false;
3155 }
3156 }
3157
3158 CellLayout.CellInfo longClickCellInfo = null;
3159 View itemUnderLongClick = null;
3160 if (v.getTag() instanceof ItemInfo) {
3161 ItemInfo info = (ItemInfo) v.getTag();
3162 longClickCellInfo = new CellLayout.CellInfo(v, info);;
3163 itemUnderLongClick = longClickCellInfo.cell;
3164 resetAddInfo();
3165 }
3166
3167 // The hotseat touch handling does not go through Workspace, and we always allow long press
3168 // on hotseat items.
3169 final boolean inHotseat = isHotseatLayout(v);
3170 boolean allowLongPress = inHotseat || mWorkspace.allowLongPress();
3171 if (allowLongPress && !mDragController.isDragging()) {
3172 if (itemUnderLongClick == null) {
3173 // User long pressed on empty space
3174 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
3175 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
3176 if (mWorkspace.isInOverviewMode()) {
3177 mWorkspace.startReordering(v);
3178 } else {
3179 mWorkspace.enterOverviewMode();
3180 }
3181 } else {
3182 final boolean isAllAppsButton = inHotseat && isAllAppsButtonRank(
3183 mHotseat.getOrderInHotseat(
3184 longClickCellInfo.cellX,
3185 longClickCellInfo.cellY));
3186 if (!(itemUnderLongClick instanceof Folder || isAllAppsButton)) {
3187 // User long pressed on an item
3188 mWorkspace.startDrag(longClickCellInfo);
3189 }
3190 }
3191 }
3192 return true;
3193 }
3194
3195 boolean isHotseatLayout(View layout) {
3196 return mHotseat != null && layout != null &&
3197 (layout instanceof CellLayout) && (layout == mHotseat.getLayout());
3198 }
3199
3200 /**
3201 * Returns the CellLayout of the specified container at the specified screen.
3202 */
3203 CellLayout getCellLayout(long container, long screenId) {
3204 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
3205 if (mHotseat != null) {
3206 return mHotseat.getLayout();
3207 } else {
3208 return null;
3209 }
3210 } else {
3211 return (CellLayout) mWorkspace.getScreenWithId(screenId);
3212 }
3213 }
3214
3215 public boolean isAllAppsVisible() {
3216 return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
3217 }
3218
3219 private void setWorkspaceBackground(boolean workspace) {
3220 mLauncherView.setBackground(workspace ?
3221 mWorkspaceBackgroundDrawable : null);
3222 }
3223
3224 protected void changeWallpaperVisiblity(boolean visible) {
3225 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
3226 int curflags = getWindow().getAttributes().flags
3227 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
3228 if (wpflags != curflags) {
3229 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
3230 }
3231 setWorkspaceBackground(visible);
3232 }
3233
3234 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) {
3235 if (v instanceof LauncherTransitionable) {
3236 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace);
3237 }
3238 }
3239
3240 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) {
3241 if (v instanceof LauncherTransitionable) {
3242 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace);
3243 }
3244
3245 // Update the workspace transition step as well
3246 dispatchOnLauncherTransitionStep(v, 0f);
3247 }
3248
3249 private void dispatchOnLauncherTransitionStep(View v, float t) {
3250 if (v instanceof LauncherTransitionable) {
3251 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t);
3252 }
3253 }
3254
3255 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) {
3256 if (v instanceof LauncherTransitionable) {
3257 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace);
3258 }
3259
3260 // Update the workspace transition step as well
3261 dispatchOnLauncherTransitionStep(v, 1f);
3262 }
3263
3264 /**
3265 * Things to test when changing the following seven functions.
3266 * - Home from workspace
3267 * - from center screen
3268 * - from other screens
3269 * - Home from all apps
3270 * - from center screen
3271 * - from other screens
3272 * - Back from all apps
3273 * - from center screen
3274 * - from other screens
3275 * - Launch app from workspace and quit
3276 * - with back
3277 * - with home
3278 * - Launch app from all apps and quit
3279 * - with back
3280 * - with home
3281 * - Go to a screen that's not the default, then all
3282 * apps, and launch and app, and go back
3283 * - with back
3284 * -with home
3285 * - On workspace, long press power and go back
3286 * - with back
3287 * - with home
3288 * - On all apps, long press power and go back
3289 * - with back
3290 * - with home
3291 * - On workspace, power off
3292 * - On all apps, power off
3293 * - Launch an app and turn off the screen while in that app
3294 * - Go back with home key
3295 * - Go back with back key TODO: make this not go to workspace
3296 * - From all apps
3297 * - From workspace
3298 * - Enter and exit car mode (becuase it causes an extra configuration changed)
3299 * - From all apps
3300 * - From the center workspace
3301 * - From another workspace
3302 */
3303
3304 /**
3305 * Zoom the camera out from the workspace to reveal 'toView'.
3306 * Assumes that the view to show is anchored at either the very top or very bottom
3307 * of the screen.
3308 */
3309 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) {
3310 AppsCustomizePagedView.ContentType contentType = mAppsCustomizeContent.getContentType();
3311 showAppsCustomizeHelper(animated, springLoaded, contentType);
3312 }
3313
3314 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded,
3315 final AppsCustomizePagedView.ContentType contentType) {
3316 if (mStateAnimation != null) {
3317 mStateAnimation.setDuration(0);
3318 mStateAnimation.cancel();
3319 mStateAnimation = null;
3320 }
3321
3322 boolean material = Utilities.isLmpOrAbove();
3323
3324 final Resources res = getResources();
3325
3326 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime);
3327 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime);
3328 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeRevealTime);
3329 final int itemsAlphaStagger =
3330 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3331
3332 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3333 final View fromView = mWorkspace;
3334 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost;
3335
3336 final ArrayList<View> layerViews = new ArrayList<View>();
3337
3338 Workspace.State workspaceState = contentType == AppsCustomizePagedView.ContentType.Widgets ?
3339 Workspace.State.OVERVIEW_HIDDEN : Workspace.State.NORMAL_HIDDEN;
3340 Animator workspaceAnim =
3341
3342 <<<<<<< LEFT
3343 mWorkspace.getChangeStateAnimation(workspaceState, animated, layerViews);
3344
3345 ||||||| BASE
3346 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
3347 =======
3348
3349 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated);
3350
3351 >>>>>>> RIGHT
3352 if (!LauncherAppState.isDisableAllApps()
3353 || contentType == AppsCustomizePagedView.ContentType.Widgets) {
3354 // Set the content type for the all apps/widgets space
3355 mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
3356 }
3357
3358 // If for some reason our views aren't initialized, don't animate
3359 boolean initialized = getAllAppsButton() != null;
3360
3361 if (animated && initialized) {
3362 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3363 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3364 toView.findViewById(R.id.apps_customize_pane_content);
3365
3366 final View page = content.getPageAt(content.getCurrentPage());
3367 final View revealView = toView.findViewById(R.id.fake_page);
3368
3369 final float initialPanelAlpha = 1f;
3370
3371 final boolean isWidgetTray = contentType == AppsCustomizePagedView.ContentType.Widgets;
3372 if (isWidgetTray) {
3373 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3374 } else {
3375 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3376 }
3377
3378 // Hide the real page background, and swap in the fake one
3379 content.setPageBackgroundsVisible(false);
3380 revealView.setVisibility(View.VISIBLE);
3381 // We need to hide this view as the animation start will be posted.
3382 revealView.setAlpha(0);
3383
3384 int width = revealView.getMeasuredWidth();
3385 int height = revealView.getMeasuredHeight();
3386 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3387
3388 revealView.setTranslationY(0);
3389 revealView.setTranslationX(0);
3390
3391 // Get the y delta between the center of the page and the center of the all apps button
3392 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3393 getAllAppsButton(), null);
3394
3395 float alpha = 0;
3396 float xDrift = 0;
3397 float yDrift = 0;
3398 if (material) {
3399 alpha = isWidgetTray ? 0.3f : 1f;
3400 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3401 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3402 } else {
3403 yDrift = 2 * height / 3;
3404 xDrift = 0;
3405 }
3406 final float initAlpha = alpha;
3407
3408 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3409 layerViews.add(revealView);
3410 PropertyValuesHolder panelAlpha = PropertyValuesHolder.ofFloat("alpha", initAlpha, 1f);
3411 PropertyValuesHolder panelDriftY =
3412 PropertyValuesHolder.ofFloat("translationY", yDrift, 0);
3413 PropertyValuesHolder panelDriftX =
3414 PropertyValuesHolder.ofFloat("translationX", xDrift, 0);
3415
3416 ObjectAnimator panelAlphaAndDrift = ObjectAnimator.ofPropertyValuesHolder(revealView,
3417 panelAlpha, panelDriftY, panelDriftX);
3418
3419 panelAlphaAndDrift.setDuration(revealDuration);
3420 panelAlphaAndDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3421
3422 mStateAnimation.play(panelAlphaAndDrift);
3423
3424 if (page != null) {
3425 page.setVisibility(View.VISIBLE);
3426 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3427 layerViews.add(page);
3428
3429 ObjectAnimator pageDrift = ObjectAnimator.ofFloat(page, "translationY", yDrift, 0);
3430 page.setTranslationY(yDrift);
3431 pageDrift.setDuration(revealDuration);
3432 pageDrift.setInterpolator(new LogDecelerateInterpolator(100, 0));
3433 pageDrift.setStartDelay(itemsAlphaStagger);
3434 mStateAnimation.play(pageDrift);
3435
3436 page.setAlpha(0f);
3437 ObjectAnimator itemsAlpha = ObjectAnimator.ofFloat(page, "alpha", 0f, 1f);
3438 itemsAlpha.setDuration(revealDuration);
3439 itemsAlpha.setInterpolator(new AccelerateInterpolator(1.5f));
3440 itemsAlpha.setStartDelay(itemsAlphaStagger);
3441 mStateAnimation.play(itemsAlpha);
3442 }
3443
3444 View pageIndicators = toView.findViewById(R.id.apps_customize_page_indicator);
3445 pageIndicators.setAlpha(0.01f);
3446 ObjectAnimator indicatorsAlpha =
3447 ObjectAnimator.ofFloat(pageIndicators, "alpha", 1f);
3448 indicatorsAlpha.setDuration(revealDuration);
3449 mStateAnimation.play(indicatorsAlpha);
3450
3451 if (material) {
3452 final View allApps = getAllAppsButton();
3453 int allAppsButtonSize = LauncherAppState.getInstance().
3454 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3455 float startRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3456 Animator reveal = ViewAnimationUtils.createCircularReveal(revealView, width / 2,
3457 height / 2, startRadius, revealRadius);
3458 reveal.setDuration(revealDuration);
3459 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3460
3461 reveal.addListener(new AnimatorListenerAdapter() {
3462 public void onAnimationStart(Animator animation) {
3463 if (!isWidgetTray) {
3464 allApps.setVisibility(View.INVISIBLE);
3465 }
3466 }
3467 public void onAnimationEnd(Animator animation) {
3468 if (!isWidgetTray) {
3469 allApps.setVisibility(View.VISIBLE);
3470 }
3471 }
3472 });
3473 mStateAnimation.play(reveal);
3474 }
3475
3476 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3477 @Override
3478 public void onAnimationEnd(Animator animation) {
3479 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3480 dispatchOnLauncherTransitionEnd(toView, animated, false);
3481
3482 revealView.setVisibility(View.INVISIBLE);
3483 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3484 if (page != null) {
3485 page.setLayerType(View.LAYER_TYPE_NONE, null);
3486 }
3487 content.setPageBackgroundsVisible(true);
3488
3489 // Hide the search bar
3490 if (mSearchDropTargetBar != null) {
3491 mSearchDropTargetBar.hideSearchBar(false);
3492 }
3493 }
3494
3495 });
3496
3497 if (workspaceAnim != null) {
3498 mStateAnimation.play(workspaceAnim);
3499 }
3500
3501 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3502 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3503 final AnimatorSet stateAnimation = mStateAnimation;
3504 final Runnable startAnimRunnable = new Runnable() {
3505 public void run() {
3506 // Check that mStateAnimation hasn't changed while
3507 // we waited for a layout/draw pass
3508 if (mStateAnimation != stateAnimation)
3509 return;
3510 dispatchOnLauncherTransitionStart(fromView, animated, false);
3511 dispatchOnLauncherTransitionStart(toView, animated, false);
3512
3513 revealView.setAlpha(initAlpha);
3514 if (Utilities.isLmpOrAbove()) {
3515 for (int i = 0; i < layerViews.size(); i++) {
3516 View v = layerViews.get(i);
3517 if (v != null) {
3518 boolean attached = true;
3519 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3520 attached = v.isAttachedToWindow();
3521 }
3522 if (attached) v.buildLayer();
3523 }
3524 }
3525 }
3526 mStateAnimation.start();
3527 }
3528 };
3529 toView.bringToFront();
3530 toView.setVisibility(View.VISIBLE);
3531 toView.post(startAnimRunnable);
3532 } else {
3533 toView.setTranslationX(0.0f);
3534 toView.setTranslationY(0.0f);
3535 toView.setScaleX(1.0f);
3536 toView.setScaleY(1.0f);
3537 toView.setVisibility(View.VISIBLE);
3538 toView.bringToFront();
3539
3540 if (!springLoaded && !LauncherAppState.getInstance().isScreenLarge()) {
3541 // Hide the search bar
3542 if (mSearchDropTargetBar != null) {
3543 mSearchDropTargetBar.hideSearchBar(false);
3544 }
3545 }
3546 dispatchOnLauncherTransitionPrepare(fromView, animated, false);
3547 dispatchOnLauncherTransitionStart(fromView, animated, false);
3548 dispatchOnLauncherTransitionEnd(fromView, animated, false);
3549 dispatchOnLauncherTransitionPrepare(toView, animated, false);
3550 dispatchOnLauncherTransitionStart(toView, animated, false);
3551 dispatchOnLauncherTransitionEnd(toView, animated, false);
3552 }
3553 }
3554
3555 /**
3556 * Zoom the camera back into the workspace, hiding 'fromView'.
3557 * This is the opposite of showAppsCustomizeHelper.
3558 * @param animated If true, the transition will be animated.
3559 */
3560 private void hideAppsCustomizeHelper(Workspace.State toState, final boolean animated,
3561 final boolean springLoaded, final Runnable onCompleteRunnable) {
3562
3563 if (mStateAnimation != null) {
3564 mStateAnimation.setDuration(0);
3565 mStateAnimation.cancel();
3566 mStateAnimation = null;
3567 }
3568
3569 boolean material = Utilities.isLmpOrAbove();
3570 Resources res = getResources();
3571
3572 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime);
3573 final int fadeOutDuration = res.getInteger(R.integer.config_appsCustomizeFadeOutTime);
3574 final int revealDuration = res.getInteger(R.integer.config_appsCustomizeConcealTime);
3575 final int itemsAlphaStagger =
3576 res.getInteger(R.integer.config_appsCustomizeItemsAlphaStagger);
3577
3578 final float scaleFactor = (float)
3579 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor);
3580 final View fromView = mAppsCustomizeTabHost;
3581 final View toView = mWorkspace;
3582 Animator workspaceAnim = null;
3583 final ArrayList<View> layerViews = new ArrayList<View>();
3584
3585 if (toState == Workspace.State.NORMAL) {
3586 workspaceAnim = mWorkspace.getChangeStateAnimation(
3587 toState, animated, layerViews);
3588 } else if (toState == Workspace.State.SPRING_LOADED ||
3589 toState == Workspace.State.OVERVIEW) {
3590 workspaceAnim = mWorkspace.getChangeStateAnimation(
3591 toState, animated, layerViews);
3592 }
3593
3594 // If for some reason our views aren't initialized, don't animate
3595 boolean initialized = getAllAppsButton() != null;
3596
3597 if (animated && initialized) {
3598 mStateAnimation = LauncherAnimUtils.createAnimatorSet();
3599 if (workspaceAnim != null) {
3600 mStateAnimation.play(workspaceAnim);
3601 }
3602
3603 final AppsCustomizePagedView content = (AppsCustomizePagedView)
3604 fromView.findViewById(R.id.apps_customize_pane_content);
3605
3606 final View page = content.getPageAt(content.getNextPage());
3607
3608 // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
3609 int count = content.getChildCount();
3610 for (int i = 0; i < count; i++) {
3611 View child = content.getChildAt(i);
3612 if (child != page) {
3613 child.setVisibility(View.INVISIBLE);
3614 }
3615 }
3616 final View revealView = fromView.findViewById(R.id.fake_page);
3617
3618 // hideAppsCustomizeHelper is called in some cases when it is already hidden
3619 // don't perform all these no-op animations. In particularly, this was causing
3620 // the all-apps button to pop in and out.
3621 if (fromView.getVisibility() == View.VISIBLE) {
3622 AppsCustomizePagedView.ContentType contentType = content.getContentType();
3623 final boolean isWidgetTray =
3624 contentType == AppsCustomizePagedView.ContentType.Widgets;
3625
3626 if (isWidgetTray) {
3627 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel_dark));
3628 } else {
3629 revealView.setBackground(res.getDrawable(R.drawable.quantum_panel));
3630 }
3631
3632 int width = revealView.getMeasuredWidth();
3633 int height = revealView.getMeasuredHeight();
3634 float revealRadius = (float) Math.sqrt((width * width) / 4 + (height * height) / 4);
3635
3636 // Hide the real page background, and swap in the fake one
3637 revealView.setVisibility(View.VISIBLE);
3638 content.setPageBackgroundsVisible(false);
3639
3640 final View allAppsButton = getAllAppsButton();
3641 revealView.setTranslationY(0);
3642 int[] allAppsToPanelDelta = Utilities.getCenterDeltaInScreenSpace(revealView,
3643 allAppsButton, null);
3644
3645 float xDrift = 0;
3646 float yDrift = 0;
3647 if (material) {
3648 yDrift = isWidgetTray ? height / 2 : allAppsToPanelDelta[1];
3649 xDrift = isWidgetTray ? 0 : allAppsToPanelDelta[0];
3650 } else {
3651 yDrift = 5 * height / 4;
3652 xDrift = 0;
3653 }
3654
3655 revealView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3656 TimeInterpolator decelerateInterpolator = material ?
3657 new LogDecelerateInterpolator(100, 0) :
3658 new LogDecelerateInterpolator(30, 0);
3659
3660 // The vertical motion of the apps panel should be delayed by one frame
3661 // from the conceal animation in order to give the right feel. We correpsondingly
3662 // shorten the duration so that the slide and conceal end at the same time.
3663 ObjectAnimator panelDriftY = LauncherAnimUtils.ofFloat(revealView, "translationY",
3664 0, yDrift);
3665 panelDriftY.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3666 panelDriftY.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3667 panelDriftY.setInterpolator(decelerateInterpolator);
3668 mStateAnimation.play(panelDriftY);
3669
3670 ObjectAnimator panelDriftX = LauncherAnimUtils.ofFloat(revealView, "translationX",
3671 0, xDrift);
3672 panelDriftX.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3673 panelDriftX.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3674 panelDriftX.setInterpolator(decelerateInterpolator);
3675 mStateAnimation.play(panelDriftX);
3676
3677 if (isWidgetTray || !material) {
3678 float finalAlpha = material ? 0.4f : 0f;
3679 revealView.setAlpha(1f);
3680 ObjectAnimator panelAlpha = LauncherAnimUtils.ofFloat(revealView, "alpha",
3681 1f, finalAlpha);
3682 panelAlpha.setDuration(revealDuration);
3683 panelAlpha.setInterpolator(material ? decelerateInterpolator :
3684 new AccelerateInterpolator(1.5f));
3685 mStateAnimation.play(panelAlpha);
3686 }
3687
3688 if (page != null) {
3689 page.setLayerType(View.LAYER_TYPE_HARDWARE, null);
3690
3691 ObjectAnimator pageDrift = LauncherAnimUtils.ofFloat(page, "translationY",
3692 0, yDrift);
3693 page.setTranslationY(0);
3694 pageDrift.setDuration(revealDuration - SINGLE_FRAME_DELAY);
3695 pageDrift.setInterpolator(decelerateInterpolator);
3696 pageDrift.setStartDelay(itemsAlphaStagger + SINGLE_FRAME_DELAY);
3697 mStateAnimation.play(pageDrift);
3698
3699 page.setAlpha(1f);
3700 ObjectAnimator itemsAlpha = LauncherAnimUtils.ofFloat(page, "alpha", 1f, 0f);
3701 itemsAlpha.setDuration(100);
3702 itemsAlpha.setInterpolator(decelerateInterpolator);
3703 mStateAnimation.play(itemsAlpha);
3704 }
3705
3706 View pageIndicators = fromView.findViewById(R.id.apps_customize_page_indicator);
3707 pageIndicators.setAlpha(1f);
3708 ObjectAnimator indicatorsAlpha =
3709 LauncherAnimUtils.ofFloat(pageIndicators, "alpha", 0f);
3710 indicatorsAlpha.setDuration(revealDuration);
3711 indicatorsAlpha.setInterpolator(new DecelerateInterpolator(1.5f));
3712 mStateAnimation.play(indicatorsAlpha);
3713
3714 width = revealView.getMeasuredWidth();
3715
3716 if (material) {
3717 if (!isWidgetTray) {
3718 allAppsButton.setVisibility(View.INVISIBLE);
3719 }
3720 int allAppsButtonSize = LauncherAppState.getInstance().
3721 getDynamicGrid().getDeviceProfile().allAppsButtonVisualSize;
3722 float finalRadius = isWidgetTray ? 0 : allAppsButtonSize / 2;
3723 Animator reveal =
3724 LauncherAnimUtils.createCircularReveal(revealView, width / 2,
3725 height / 2, revealRadius, finalRadius);
3726 reveal.setInterpolator(new LogDecelerateInterpolator(100, 0));
3727 reveal.setDuration(revealDuration);
3728 reveal.setStartDelay(itemsAlphaStagger);
3729
3730 reveal.addListener(new AnimatorListenerAdapter() {
3731 public void onAnimationEnd(Animator animation) {
3732 revealView.setVisibility(View.INVISIBLE);
3733 if (!isWidgetTray) {
3734 allAppsButton.setVisibility(View.VISIBLE);
3735 }
3736 }
3737 });
3738
3739 mStateAnimation.play(reveal);
3740 }
3741
3742 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3743 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3744 mAppsCustomizeContent.stopScrolling();
3745 }
3746
3747 mStateAnimation.addListener(new AnimatorListenerAdapter() {
3748 @Override
3749 public void onAnimationEnd(Animator animation) {
3750 fromView.setVisibility(View.GONE);
3751 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3752 dispatchOnLauncherTransitionEnd(toView, animated, true);
3753 if (onCompleteRunnable != null) {
3754 onCompleteRunnable.run();
3755 }
3756
3757 revealView.setLayerType(View.LAYER_TYPE_NONE, null);
3758 if (page != null) {
3759 page.setLayerType(View.LAYER_TYPE_NONE, null);
3760 }
3761 content.setPageBackgroundsVisible(true);
3762 // Unhide side pages
3763 int count = content.getChildCount();
3764 for (int i = 0; i < count; i++) {
3765 View child = content.getChildAt(i);
3766 child.setVisibility(View.VISIBLE);
3767 }
3768
3769 // Reset page transforms
3770 if (page != null) {
3771 page.setTranslationX(0);
3772 page.setTranslationY(0);
3773 page.setAlpha(1);
3774 }
3775 content.setCurrentPage(content.getNextPage());
3776
3777 mAppsCustomizeContent.updateCurrentPageScroll();
3778 }
3779 });
3780
3781 final AnimatorSet stateAnimation = mStateAnimation;
3782 final Runnable startAnimRunnable = new Runnable() {
3783 public void run() {
3784 // Check that mStateAnimation hasn't changed while
3785 // we waited for a layout/draw pass
3786 if (mStateAnimation != stateAnimation)
3787 return;
3788 dispatchOnLauncherTransitionStart(fromView, animated, false);
3789 dispatchOnLauncherTransitionStart(toView, animated, false);
3790
3791 if (Utilities.isLmpOrAbove()) {
3792 for (int i = 0; i < layerViews.size(); i++) {
3793 View v = layerViews.get(i);
3794 if (v != null) {
3795 boolean attached = true;
3796 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
3797 attached = v.isAttachedToWindow();
3798 }
3799 if (attached) v.buildLayer();
3800 }
3801 }
3802 }
3803 mStateAnimation.start();
3804 }
3805 };
3806 fromView.post(startAnimRunnable);
3807 } else {
3808 fromView.setVisibility(View.GONE);
3809 dispatchOnLauncherTransitionPrepare(fromView, animated, true);
3810 dispatchOnLauncherTransitionStart(fromView, animated, true);
3811 dispatchOnLauncherTransitionEnd(fromView, animated, true);
3812 dispatchOnLauncherTransitionPrepare(toView, animated, true);
3813 dispatchOnLauncherTransitionStart(toView, animated, true);
3814 dispatchOnLauncherTransitionEnd(toView, animated, true);
3815 }
3816 }
3817
3818 @Override
3819 public void onTrimMemory(int level) {
3820 super.onTrimMemory(level);
3821 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
3822 mAppsCustomizeTabHost.onTrimMemory();
3823 }
3824 }
3825
3826 protected void showWorkspace(boolean animated) {
3827 showWorkspace(animated, null);
3828 }
3829
3830 protected void showWorkspace() {
3831 showWorkspace(true);
3832 }
3833
3834 void showWorkspace(boolean animated, Runnable onCompleteRunnable) {
3835 if (mState != State.WORKSPACE || mWorkspace.getState() != Workspace.State.NORMAL) {
3836 boolean wasInSpringLoadedMode = (mState != State.WORKSPACE);
3837 mWorkspace.setVisibility(View.VISIBLE);
3838 hideAppsCustomizeHelper(Workspace.State.NORMAL, animated, false, onCompleteRunnable);
3839
3840 // Show the search bar (only animate if we were showing the drop target bar in spring
3841 // loaded mode)
3842 if (mSearchDropTargetBar != null) {
3843 mSearchDropTargetBar.showSearchBar(animated && wasInSpringLoadedMode);
3844 }
3845
3846 // Set focus to the AppsCustomize button
3847 if (mAllAppsButton != null) {
3848 mAllAppsButton.requestFocus();
3849 }
3850 }
3851
3852 // Change the state *after* we've called all the transition code
3853 mState = State.WORKSPACE;
3854
3855 // Resume the auto-advance of widgets
3856 mUserPresent = true;
3857 updateRunning();
3858
3859 // Send an accessibility event to announce the context change
3860 getWindow().getDecorView()
3861 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3862
3863 onWorkspaceShown(animated);
3864 }
3865
3866 void showOverviewMode(boolean animated) {
3867 mWorkspace.setVisibility(View.VISIBLE);
3868 hideAppsCustomizeHelper(Workspace.State.OVERVIEW, animated, false, null);
3869 mState = State.WORKSPACE;
3870 onWorkspaceShown(animated);
3871 }
3872
3873 public void onWorkspaceShown(boolean animated) {
3874 }
3875
3876 void showAllApps(boolean animated, AppsCustomizePagedView.ContentType contentType,
3877 boolean resetPageToZero) {
3878 if (mState != State.WORKSPACE) return;
3879
3880 if (resetPageToZero) {
3881 mAppsCustomizeTabHost.reset();
3882 }
3883 showAppsCustomizeHelper(animated, false, contentType);
3884 mAppsCustomizeTabHost.post(new Runnable() {
3885 @Override
3886 public void run() {
3887 // We post this in-case the all apps view isn't yet constructed.
3888 mAppsCustomizeTabHost.requestFocus();
3889 }
3890 });
3891
3892 // Change the state *after* we've called all the transition code
3893 mState = State.APPS_CUSTOMIZE;
3894
3895 // Pause the auto-advance of widgets until we are out of AllApps
3896 mUserPresent = false;
3897 updateRunning();
3898 closeFolder();
3899
3900 // Send an accessibility event to announce the context change
3901 getWindow().getDecorView()
3902 .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
3903 }
3904
3905 void enterSpringLoadedDragMode() {
3906 if (isAllAppsVisible()) {
3907 hideAppsCustomizeHelper(Workspace.State.SPRING_LOADED, true, true, null);
3908 mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
3909 }
3910 }
3911
3912 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay,
3913 final Runnable onCompleteRunnable) {
3914 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return;
3915
3916 mHandler.postDelayed(new Runnable() {
3917 @Override
3918 public void run() {
3919 if (successfulDrop) {
3920 // Before we show workspace, hide all apps again because
3921 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should
3922 // clean up our state transition functions
3923 mAppsCustomizeTabHost.setVisibility(View.GONE);
3924 showWorkspace(true, onCompleteRunnable);
3925 } else {
3926 exitSpringLoadedDragMode();
3927 }
3928 }
3929 }, delay);
3930 }
3931
3932 void exitSpringLoadedDragMode() {
3933 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) {
3934 final boolean animated = true;
3935 final boolean springLoaded = true;
3936 showAppsCustomizeHelper(animated, springLoaded);
3937 mState = State.APPS_CUSTOMIZE;
3938 }
3939 // Otherwise, we are not in spring loaded mode, so don't do anything.
3940 }
3941
3942 void lockAllApps() {
3943 // TODO
3944 }
3945
3946 void unlockAllApps() {
3947 // TODO
3948 }
3949
3950 /**
3951 * Hides the hotseat area.
3952 */
3953 void hideHotseat(boolean animated) {
3954 if (!LauncherAppState.getInstance().isScreenLarge()) {
3955 if (animated) {
3956 if (mHotseat.getAlpha() != 0f) {
3957 int duration = 0;
3958 if (mSearchDropTargetBar != null) {
3959 duration = mSearchDropTargetBar.getTransitionOutDuration();
3960 }
3961 mHotseat.animate().alpha(0f).setDuration(duration);
3962 }
3963 } else {
3964 mHotseat.setAlpha(0f);
3965 }
3966 }
3967 }
3968
3969 /**
3970 * Add an item from all apps or customize onto the given workspace screen.
3971 * If layout is null, add to the current screen.
3972 */
3973 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) {
3974 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) {
3975 showOutOfSpaceMessage(isHotseatLayout(layout));
3976 }
3977 }
3978
3979 /** Maps the current orientation to an index for referencing orientation correct global icons */
3980 private int getCurrentOrientationIndexForGlobalIcons() {
3981 // default - 0, landscape - 1
3982 switch (getResources().getConfiguration().orientation) {
3983 case Configuration.ORIENTATION_LANDSCAPE:
3984 return 1;
3985 default:
3986 return 0;
3987 }
3988 }
3989
3990 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) {
3991 try {
3992 PackageManager packageManager = getPackageManager();
3993 // Look for the toolbar icon specified in the activity meta-data
3994 Bundle metaData = packageManager.getActivityInfo(
3995 activityName, PackageManager.GET_META_DATA).metaData;
3996 if (metaData != null) {
3997 int iconResId = metaData.getInt(resourceName);
3998 if (iconResId != 0) {
3999 Resources res = packageManager.getResourcesForActivity(activityName);
4000 return res.getDrawable(iconResId);
4001 }
4002 }
4003 } catch (NameNotFoundException e) {
4004 // This can happen if the activity defines an invalid drawable
4005 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() +
4006 " not found", e);
4007 } catch (Resources.NotFoundException nfe) {
4008 // This can happen if the activity defines an invalid drawable
4009 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(),
4010 nfe);
4011 }
4012 return null;
4013 }
4014
4015 // if successful in getting icon, return it; otherwise, set button to use default drawable
4016 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity(
4017 int buttonId, ComponentName activityName, int fallbackDrawableId,
4018 String toolbarResourceName) {
4019 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
4020 Resources r = getResources();
4021 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width);
4022 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height);
4023
4024 TextView button = (TextView) findViewById(buttonId);
4025 // If we were unable to find the icon via the meta-data, use a generic one
4026 if (toolbarIcon == null) {
4027 toolbarIcon = r.getDrawable(fallbackDrawableId);
4028 toolbarIcon.setBounds(0, 0, w, h);
4029 if (button != null) {
4030 button.setCompoundDrawables(toolbarIcon, null, null, null);
4031 }
4032 return null;
4033 } else {
4034 toolbarIcon.setBounds(0, 0, w, h);
4035 if (button != null) {
4036 button.setCompoundDrawables(toolbarIcon, null, null, null);
4037 }
4038 return toolbarIcon.getConstantState();
4039 }
4040 }
4041
4042 // if successful in getting icon, return it; otherwise, set button to use default drawable
4043 private Drawable.ConstantState updateButtonWithIconFromExternalActivity(
4044 int buttonId, ComponentName activityName, int fallbackDrawableId,
4045 String toolbarResourceName) {
4046 ImageView button = (ImageView) findViewById(buttonId);
4047 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName);
4048
4049 if (button != null) {
4050 // If we were unable to find the icon via the meta-data, use a
4051 // generic one
4052 if (toolbarIcon == null) {
4053 button.setImageResource(fallbackDrawableId);
4054 } else {
4055 button.setImageDrawable(toolbarIcon);
4056 }
4057 }
4058
4059 return toolbarIcon != null ? toolbarIcon.getConstantState() : null;
4060
4061 }
4062
4063 private void updateTextButtonWithDrawable(int buttonId, Drawable d) {
4064 TextView button = (TextView) findViewById(buttonId);
4065 button.setCompoundDrawables(d, null, null, null);
4066 }
4067
4068 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) {
4069 ImageView button = (ImageView) findViewById(buttonId);
4070 button.setImageDrawable(d.newDrawable(getResources()));
4071 }
4072
4073 private void invalidatePressedFocusedStates(View container, View button) {
4074 if (container instanceof HolographicLinearLayout) {
4075 HolographicLinearLayout layout = (HolographicLinearLayout) container;
4076 layout.invalidatePressedFocusedStates();
4077 } else if (button instanceof HolographicImageView) {
4078 HolographicImageView view = (HolographicImageView) button;
4079 view.invalidatePressedFocusedStates();
4080 }
4081 }
4082
4083 public View getQsbBar() {
4084 if (mQsb == null) {
4085 mQsb = mInflater.inflate(R.layout.qsb, mSearchDropTargetBar, false);
4086 mSearchDropTargetBar.addView(mQsb);
4087 }
4088 return mQsb;
4089 }
4090
4091 protected boolean updateGlobalSearchIcon() {
4092 final View searchButtonContainer = findViewById(R.id.search_button_container);
4093 final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
4094 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4095 final View voiceButton = findViewById(R.id.voice_button);
4096
4097 final SearchManager searchManager =
4098 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4099 ComponentName activityName = searchManager.getGlobalSearchActivity();
4100 if (activityName != null) {
4101 int coi = getCurrentOrientationIndexForGlobalIcons();
4102 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4103 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4104 TOOLBAR_SEARCH_ICON_METADATA_NAME);
4105 if (sGlobalSearchIcon[coi] == null) {
4106 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4107 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
4108 TOOLBAR_ICON_METADATA_NAME);
4109 }
4110
4111 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
4112 searchButton.setVisibility(View.VISIBLE);
4113 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4114 return true;
4115 } else {
4116 // We disable both search and voice search when there is no global search provider
4117 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
4118 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4119 if (searchButton != null) searchButton.setVisibility(View.GONE);
4120 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4121 updateVoiceButtonProxyVisible(false);
4122 return false;
4123 }
4124 }
4125
4126 protected void updateGlobalSearchIcon(Drawable.ConstantState d) {
4127 final View searchButtonContainer = findViewById(R.id.search_button_container);
4128 final View searchButton = (ImageView) findViewById(R.id.search_button);
4129 updateButtonWithDrawable(R.id.search_button, d);
4130 invalidatePressedFocusedStates(searchButtonContainer, searchButton);
4131 }
4132
4133 protected boolean updateVoiceSearchIcon(boolean searchVisible) {
4134 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4135 final View voiceButton = findViewById(R.id.voice_button);
4136
4137 // We only show/update the voice search icon if the search icon is enabled as well
4138 final SearchManager searchManager =
4139 (SearchManager) getSystemService(Context.SEARCH_SERVICE);
4140 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
4141
4142 ComponentName activityName = null;
4143 if (globalSearchActivity != null) {
4144 // Check if the global search activity handles voice search
4145 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4146 intent.setPackage(globalSearchActivity.getPackageName());
4147 activityName = intent.resolveActivity(getPackageManager());
4148 }
4149
4150 if (activityName == null) {
4151 // Fallback: check if an activity other than the global search activity
4152 // resolves this
4153 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
4154 activityName = intent.resolveActivity(getPackageManager());
4155 }
4156 if (searchVisible && activityName != null) {
4157 int coi = getCurrentOrientationIndexForGlobalIcons();
4158 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4159 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4160 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME);
4161 if (sVoiceSearchIcon[coi] == null) {
4162 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
4163 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo,
4164 TOOLBAR_ICON_METADATA_NAME);
4165 }
4166 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
4167 voiceButton.setVisibility(View.VISIBLE);
4168 updateVoiceButtonProxyVisible(false);
4169 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4170 return true;
4171 } else {
4172 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
4173 if (voiceButton != null) voiceButton.setVisibility(View.GONE);
4174 updateVoiceButtonProxyVisible(false);
4175 return false;
4176 }
4177 }
4178
4179 protected void updateVoiceSearchIcon(Drawable.ConstantState d) {
4180 final View voiceButtonContainer = findViewById(R.id.voice_button_container);
4181 final View voiceButton = findViewById(R.id.voice_button);
4182 updateButtonWithDrawable(R.id.voice_button, d);
4183 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
4184 }
4185
4186 public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
4187 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
4188 if (voiceButtonProxy != null) {
4189 boolean visible = !forceDisableVoiceButtonProxy &&
4190 mWorkspace.shouldVoiceButtonProxyBeVisible();
4191 voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
4192 voiceButtonProxy.bringToFront();
4193 }
4194 }
4195
4196 /**
4197 * This is an overrid eot disable the voice button proxy. If disabled is true, then the voice button🔵
4198 * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
4199 */
4200 public void disableVoiceButtonProxy(boolean disabled) {
4201 updateVoiceButtonProxyVisible(disabled);
4202 }
4203
4204 @Override
4205 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
4206 final boolean result = super.dispatchPopulateAccessibilityEvent(event);
4207 final List<CharSequence> text = event.getText();
4208 text.clear();
4209 // Populate event with a fake title based on the current state.
4210 if (mState == State.APPS_CUSTOMIZE) {
4211 text.add(mAppsCustomizeTabHost.getContentTag());
4212 } else {
4213 text.add(getString(R.string.all_apps_home_button_label));
4214 }
4215 return result;
4216 }
4217
4218 /**
4219 * Receives notifications when system dialogs are to be closed.
4220 */
4221 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
4222 @Override
4223 public void onReceive(Context context, Intent intent) {
4224 closeSystemDialogs();
4225 }
4226 }
4227
4228 /**
4229 * Receives notifications whenever the appwidgets are reset.
4230 */
4231 private class AppWidgetResetObserver extends ContentObserver {
4232 public AppWidgetResetObserver() {
4233 super(new Handler());
4234 }
4235
4236 @Override
4237 public void onChange(boolean selfChange) {
4238 onAppWidgetReset();
4239 }
4240 }
4241
4242 /**
4243 * If the activity is currently paused, signal that we need to run the passed Runnable
4244 * in onResume.
4245 *
4246 * This needs to be called from incoming places where resources might have been loaded
4247 * while we are paused. That is becaues the Configuration might be wrong
4248 * when we're not running, and if it comes back to what it was when we
4249 * were paused, we are not restarted.
4250 *
4251 * Implementation of the method from LauncherModel.Callbacks.
4252 *
4253 * @return true if we are currently paused. The caller might be able to
4254 * skip some work in that case since we will come back again.
4255 */
4256 private boolean waitUntilResume(Runnable run, boolean deletePreviousRunnables) {
4257 if (mPaused) {
4258 Log.i(TAG, "Deferring update until onResume");
4259 if (deletePreviousRunnables) {
4260 while (mBindOnResumeCallbacks.remove(run)) {
4261 }
4262 }
4263 mBindOnResumeCallbacks.add(run);
4264 return true;
4265 } else {
4266 return false;
4267 }
4268 }
4269
4270 private boolean waitUntilResume(Runnable run) {
4271 return waitUntilResume(run, false);
4272 }
4273
4274 public void addOnResumeCallback(Runnable run) {
4275 mOnResumeCallbacks.add(run);
4276 }
4277
4278 /**
4279 * If the activity is currently paused, signal that we need to re-run the loader
4280 * in onResume.
4281 *
4282 * This needs to be called from incoming places where resources might have been loaded
4283 * while we are paused. That is becaues the Configuration might be wrong
4284 * when we're not running, and if it comes back to what it was when we
4285 * were paused, we are not restarted.
4286 *
4287 * Implementation of the method from LauncherModel.Callbacks.
4288 *
4289 * @return true if we are currently paused. The caller might be able to
4290 * skip some work in that case since we will come back again.
4291 */
4292 public boolean setLoadOnResume() {
4293 if (mPaused) {
4294 Log.i(TAG, "setLoadOnResume");
4295 mOnResumeNeedsLoad = true;
4296 return true;
4297 } else {
4298 return false;
4299 }
4300 }
4301
4302 /**
4303 * Implementation of the method from LauncherModel.Callbacks.
4304 */
4305 public int getCurrentWorkspaceScreen() {
4306 if (mWorkspace != null) {
4307 return mWorkspace.getCurrentPage();
4308 } else {
4309 return SCREEN_COUNT / 2;
4310 }
4311 }
4312
4313 /**
4314 * Refreshes the shortcuts shown on the workspace.
4315 *
4316 * Implementation of the method from LauncherModel.Callbacks.
4317 */
4318 public void startBinding() {
4319 setWorkspaceLoading(true);
4320
4321 // If we're starting binding all over again, clear any bind calls we'd postponed in
4322 // the past (see waitUntilResume) -- we don't need them since we're starting binding
4323 // from scratch again
4324 mBindOnResumeCallbacks.clear();
4325
4326 // Clear the workspace because it's going to be rebound
4327 mWorkspace.clearDropTargets();
4328 mWorkspace.removeAllWorkspaceScreens();
4329
4330 mWidgetsToAdvance.clear();
4331 if (mHotseat != null) {
4332 mHotseat.resetLayout();
4333 }
4334 }
4335
4336 @Override
4337 public void bindScreens(ArrayList<Long> orderedScreenIds) {
4338 bindAddScreens(orderedScreenIds);
4339
4340 // If there are no screens, we need to have an empty screen
4341 if (orderedScreenIds.size() == 0) {
4342 mWorkspace.addExtraEmptyScreen();
4343 }
4344
4345 // Create the custom content page (this call updates mDefaultScreen which calls
4346 // setCurrentPage() so ensure that all pages are added before calling this).
4347 if (hasCustomContentToLeft()) {
4348 mWorkspace.createCustomContentContainer();
4349 populateCustomContentContainer();
4350 }
4351 }
4352
4353 @Override
4354 public void bindAddScreens(ArrayList<Long> orderedScreenIds) {
4355 // Log to disk
4356 Launcher.addDumpLog(TAG, "11683562 - bindAddScreens()", true);
4357 Launcher.addDumpLog(TAG, "11683562 - orderedScreenIds: " +
4358 TextUtils.join(", ", orderedScreenIds), true);
4359 int count = orderedScreenIds.size();
4360 for (int i = 0; i < count; i++) {
4361 mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(orderedScreenIds.get(i));
4362 }
4363 }
4364
4365 private boolean shouldShowWeightWatcher() {
4366 String spKey = LauncherAppState.getSharedPreferencesKey();
4367 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4368 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, SHOW_WEIGHT_WATCHER_DEFAULT);
4369
4370 return show;
4371 }
4372
4373 private void toggleShowWeightWatcher() {
4374 String spKey = LauncherAppState.getSharedPreferencesKey();
4375 SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
4376 boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
4377
4378 show = !show;
4379
4380 SharedPreferences.Editor editor = sp.edit();
4381 editor.putBoolean(SHOW_WEIGHT_WATCHER, show);
4382 editor.commit();
4383
4384 if (mWeightWatcher != null) {
4385 mWeightWatcher.setVisibility(show ? View.VISIBLE : View.GONE);
4386 }
4387 }
4388
4389 public void bindAppsAdded(final ArrayList<Long> newScreens,
4390 final ArrayList<ItemInfo> addNotAnimated,
4391 final ArrayList<ItemInfo> addAnimated,
4392 final ArrayList<AppInfo> addedApps) {
4393 Runnable r = new Runnable() {
4394 public void run() {
4395 bindAppsAdded(newScreens, addNotAnimated, addAnimated, addedApps);
4396 }
4397 };
4398 if (waitUntilResume(r)) {
4399 return;
4400 }
4401
4402 // Add the new screens
4403 if (newScreens != null) {
4404 bindAddScreens(newScreens);
4405 }
4406
4407 // We add the items without animation on non-visible pages, and with
4408 // animations on the new page (which we will try and snap to).
4409 if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
4410 bindItems(addNotAnimated, 0,
4411 addNotAnimated.size(), false);
4412 }
4413 if (addAnimated != null && !addAnimated.isEmpty()) {
4414 bindItems(addAnimated, 0,
4415 addAnimated.size(), true);
4416 }
4417
4418 // Remove the extra empty screen
4419 mWorkspace.removeExtraEmptyScreen(false, false);
4420
4421 if (!LauncherAppState.isDisableAllApps() &&
4422 addedApps != null && mAppsCustomizeContent != null) {
4423 mAppsCustomizeContent.addApps(addedApps);
4424 }
4425 }
4426
4427 /**
4428 * Bind the items start-end from the list.
4429 *
4430 * Implementation of the method from LauncherModel.Callbacks.
4431 */
4432 public void bindItems(final ArrayList<ItemInfo> shortcuts, final int start, final int end,
4433 final boolean forceAnimateIcons) {
4434 Runnable r = new Runnable() {
4435 public void run() {
4436 bindItems(shortcuts, start, end, forceAnimateIcons);
4437 }
4438 };
4439 if (waitUntilResume(r)) {
4440 return;
4441 }
4442
4443 // Get the list of added shortcuts and intersect them with the set of shortcuts here
4444 final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet();
4445 final Collection<Animator> bounceAnims = new ArrayList<Animator>();
4446 final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation();
4447 Workspace workspace = mWorkspace;
4448 long newShortcutsScreenId = -1;
4449 for (int i = start; i < end; i++) {
4450 final ItemInfo item = shortcuts.get(i);
4451
4452 // Short circuit if we are loading dock items for a configuration which has no dock
4453 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT &&
4454 mHotseat == null) {
4455 continue;
4456 }
4457
4458 switch (item.itemType) {
4459 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
4460 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
4461 ShortcutInfo info = (ShortcutInfo) item;
4462 View shortcut = createShortcut(info);
4463
4464 /*
4465 * TODO: FIX collision case
4466 */
4467 if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
4468 CellLayout cl = mWorkspace.getScreenWithId(item.screenId);
4469 if (cl != null && cl.isOccupied(item.cellX, item.cellY)) {
4470 View v = cl.getChildAt(item.cellX, item.cellY);
4471 Object tag = v.getTag();
4472 String desc = "Collision while binding workspace item: " + item
4473 + ". Collides with " + tag;
4474 if (LauncherAppState.isDogfoodBuild()) {
4475 throw (new RuntimeException(desc));
4476 } else {
4477 Log.d(TAG, desc);
4478 }
4479 }
4480 }
4481
4482 workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX,
4483 item.cellY, 1, 1);
4484 if (animateIcons) {
4485 // Animate all the applications up now
4486 shortcut.setAlpha(0f);
4487 shortcut.setScaleX(0f);
4488 shortcut.setScaleY(0f);
4489 bounceAnims.add(createNewAppBounceAnimation(shortcut, i));
4490 newShortcutsScreenId = item.screenId;
4491 }
4492 break;
4493 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
4494 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
4495 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()),
4496 (FolderInfo) item, mIconCache);
4497 workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
4498 item.cellY, 1, 1);
4499 break;
4500 default:
4501 throw new RuntimeException("Invalid Item Type");
4502 }
4503 }
4504
4505 if (animateIcons) {
4506 // Animate to the correct page
4507 if (newShortcutsScreenId > -1) {
4508 long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage());
4509 final int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId);
4510 final Runnable startBounceAnimRunnable = new Runnable() {
4511 public void run() {
4512 anim.playTogether(bounceAnims);
4513 anim.start();
4514 }
4515 };
4516 if (newShortcutsScreenId != currentScreenId) {
4517 // We post the animation slightly delayed to prevent slowdowns
4518 // when we are loading right after we return to launcher.
4519 mWorkspace.postDelayed(new Runnable() {
4520 public void run() {
4521 if (mWorkspace != null) {
4522 mWorkspace.snapToPage(newScreenIndex);
4523 mWorkspace.postDelayed(startBounceAnimRunnable,
4524 NEW_APPS_ANIMATION_DELAY);
4525 }
4526 }
4527 }, NEW_APPS_PAGE_MOVE_DELAY);
4528 } else {
4529 mWorkspace.postDelayed(startBounceAnimRunnable, NEW_APPS_ANIMATION_DELAY);
4530 }
4531 }
4532 }
4533 workspace.requestLayout();
4534 }
4535
4536 /**
4537 * Implementation of the method from LauncherModel.Callbacks.
4538 */
4539 public void bindFolders(final HashMap<Long, FolderInfo> folders) {
4540 Runnable r = new Runnable() {
4541 public void run() {
4542 bindFolders(folders);
4543 }
4544 };
4545 if (waitUntilResume(r)) {
4546 return;
4547 }
4548 sFolders.clear();
4549 sFolders.putAll(folders);
4550 }
4551
4552 /**
4553 * Add the views for a widget to the workspace.
4554 *
4555 * Implementation of the method from LauncherModel.Callbacks.
4556 */
4557 public void bindAppWidget(final LauncherAppWidgetInfo item) {
4558 Runnable r = new Runnable() {
4559 public void run() {
4560 bindAppWidget(item);
4561 }
4562 };
4563 if (waitUntilResume(r)) {
4564 return;
4565 }
4566
4567 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
4568 if (DEBUG_WIDGETS) {
4569 Log.d(TAG, "bindAppWidget: " + item);
4570 }
4571 final Workspace workspace = mWorkspace;
4572
4573 AppWidgetProviderInfo appWidgetInfo;
4574 if (((item.restoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0) &&
4575 ((item.restoreStatus & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID) != 0)) {
4576
4577 appWidgetInfo = mModel.findAppWidgetProviderInfoWithComponent(this, item.providerName);
4578 if (appWidgetInfo == null) {
4579 if (DEBUG_WIDGETS) {
4580 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4581 + " belongs to component " + item.providerName
4582 + ", as the povider is null");
4583 }
4584 LauncherModel.deleteItemFromDatabase(this, item);
4585 return;
4586 }
4587 // Note: This assumes that the id remap broadcast is received before this step.
4588 // If that is not the case, the id remap will be ignored and user may see the
4589 // click to setup view.
4590 PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(appWidgetInfo, null, null);
4591 pendingInfo.spanX = item.spanX;
4592 pendingInfo.spanY = item.spanY;
4593 pendingInfo.minSpanX = item.minSpanX;
4594 pendingInfo.minSpanY = item.minSpanY;
4595 Bundle options =
4596 AppsCustomizePagedView.getDefaultOptionsForWidget(this, pendingInfo);
4597
4598 int newWidgetId = mAppWidgetHost.allocateAppWidgetId();
4599 boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(
4600 newWidgetId, appWidgetInfo, options);
4601
4602 // TODO consider showing a permission dialog when the widget is clicked.
4603 if (!success) {
4604 mAppWidgetHost.deleteAppWidgetId(newWidgetId);
4605 if (DEBUG_WIDGETS) {
4606 Log.d(TAG, "Removing restored widget: id=" + item.appWidgetId
4607 + " belongs to component " + item.providerName
4608 + ", as the launcher is unable to bing a new widget id");
4609 }
4610 LauncherModel.deleteItemFromDatabase(this, item);
4611 return;
4612 }
4613
4614 item.appWidgetId = newWidgetId;
4615
4616 // If the widget has a configure activity, it is still needs to set it up, otherwise
4617 // the widget is ready to go.
4618 item.restoreStatus = (appWidgetInfo.configure == null)
4619 ? LauncherAppWidgetInfo.RESTORE_COMPLETED
4620 : LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
4621
4622 LauncherModel.updateItemInDatabase(this, item);
4623 }
4624
4625 if (item.restoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED) {
4626 final int appWidgetId = item.appWidgetId;
4627 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
4628 if (DEBUG_WIDGETS) {
4629 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidget🔵
4630 }
4631
4632 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
4633 } else {
4634 appWidgetInfo = null;
4635 PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item);
4636 view.updateIcon(mIconCache);
4637 item.hostView = view;
4638 item.hostView.updateAppWidget(null);
4639 item.hostView.setOnClickListener(this);
4640 }
4641
4642 item.hostView.setTag(item);
4643 item.onBindAppWidget(this);
4644
4645 workspace.addInScreen(item.hostView, item.container, item.screenId, item.cellX,
4646 item.cellY, item.spanX, item.spanY, false);
4647 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
4648
4649 workspace.requestLayout();
4650
4651 if (DEBUG_WIDGETS) {
4652 Log.d(TAG, "bound widget id="+item.appWidgetId+" in "
4653 + (SystemClock.uptimeMillis()-start) + "ms");
4654 }
4655 }
4656
4657 /**
4658 * Restores a pending widget.
4659 *
4660 * @param appWidgetId The app widget id
4661 * @param cellInfo The position on screen where to create the widget.
4662 */
4663 private void completeRestoreAppWidget(final int appWidgetId) {
4664 LauncherAppWidgetHostView view = mWorkspace.getWidgetForAppWidgetId(appWidgetId);
4665 if ((view == null) || !(view instanceof PendingAppWidgetHostView)) {
4666 Log.e(TAG, "Widget update called, when the widget no longer exists.");
4667 return;
4668 }
4669
4670 LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) view.getTag();
4671 info.restoreStatus = LauncherAppWidgetInfo.RESTORE_COMPLETED;
4672
4673 mWorkspace.reinflateWidgetsIfNecessary();
4674 LauncherModel.updateItemInDatabase(this, info);
4675 }
4676
4677 public void onPageBoundSynchronously(int page) {
4678 mSynchronouslyBoundPages.add(page);
4679 }
4680
4681 /**
4682 * Callback saying that there aren't any more items to bind.
4683 *
4684 * Implementation of the method from LauncherModel.Callbacks.
4685 */
4686 public void finishBindingItems(final boolean upgradePath) {
4687 Runnable r = new Runnable() {
4688 public void run() {
4689 finishBindingItems(upgradePath);
4690 }
4691 };
4692 if (waitUntilResume(r)) {
4693 return;
4694 }
4695 if (mSavedState != null) {
4696 if (!mWorkspace.hasFocus()) {
4697 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus();
4698 }
4699 mSavedState = null;
4700 }
4701
4702 mWorkspace.restoreInstanceStateForRemainingPages();
4703
4704 setWorkspaceLoading(false);
4705 sendLoadingCompleteBroadcastIfNecessary();
4706
4707 // If we received the result of any pending adds while the loader was running (e.g. the
4708 // widget configuration forced an orientation change), process them now.
4709 if (sPendingAddItem != null) {
4710 final long screenId = completeAdd(sPendingAddItem);
4711
4712 // TODO: this moves the user to the page where the pending item was added. Ideally,
4713 // the screen would be guaranteed to exist after bind, and the page would be set through
4714 // the workspace restore process.
4715 mWorkspace.post(new Runnable() {
4716 @Override
4717 public void run() {
4718 mWorkspace.snapToScreenId(screenId);
4719 }
4720 });
4721 sPendingAddItem = null;
4722 }
4723
4724 if (upgradePath) {
4725 mWorkspace.getUniqueComponents(true, null);
4726 mIntentsOnWorkspaceFromUpgradePath = mWorkspace.getUniqueComponents(true, null);
4727 }
4728 PackageInstallerCompat.getInstance(this).onFinishBind();
4729 mModel.recheckRestoredItems(this);
4730 }
4731
4732 private void sendLoadingCompleteBroadcastIfNecessary() {
4733 if (!mSharedPrefs.getBoolean(FIRST_LOAD_COMPLETE, false)) {
4734 String permission =
4735 getResources().getString(R.string.receive_first_load_broadcast_permission);
4736 Intent intent = new Intent(ACTION_FIRST_LOAD_COMPLETE);
4737 sendBroadcast(intent, permission);
4738 SharedPreferences.Editor editor = mSharedPrefs.edit();
4739 editor.putBoolean(FIRST_LOAD_COMPLETE, true);
4740 editor.apply();
4741 }
4742 }
4743
4744 public boolean isAllAppsButtonRank(int rank) {
4745 if (mHotseat != null) {
4746 return mHotseat.isAllAppsButtonRank(rank);
4747 }
4748 return false;
4749 }
4750
4751 private boolean canRunNewAppsAnimation() {
4752 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime();
4753 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000);
4754 }
4755
4756 private ValueAnimator createNewAppBounceAnimation(View v, int i) {
4757 ValueAnimator bounceAnim = LauncherAnimUtils.ofPropertyValuesHolder(v,
4758 PropertyValuesHolder.ofFloat("alpha", 1f),
4759 PropertyValuesHolder.ofFloat("scaleX", 1f),
4760 PropertyValuesHolder.ofFloat("scaleY", 1f));
4761 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION);
4762 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY);
4763 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator());
4764 return bounceAnim;
4765 }
4766
4767 public boolean useVerticalBarLayout() {
4768 return LauncherAppState.getInstance().getDynamicGrid().
4769 getDeviceProfile().isVerticalBarLayout();
4770 }
4771
4772 protected Rect getSearchBarBounds() {
4773 return LauncherAppState.getInstance().getDynamicGrid().
4774 getDeviceProfile().getSearchBarBounds();
4775 }
4776
4777 @Override
4778 public void bindSearchablesChanged() {
4779 boolean searchVisible = updateGlobalSearchIcon();
4780 boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
4781 if (mSearchDropTargetBar != null) {
4782 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
4783 }
4784 }
4785
4786 /**
4787 * Add the icons for all apps.
4788 *
4789 * Implementation of the method from LauncherModel.Callbacks.
4790 */
4791 public void bindAllApplications(final ArrayList<AppInfo> apps) {
4792 if (LauncherAppState.isDisableAllApps()) {
4793 if (mIntentsOnWorkspaceFromUpgradePath != null) {
4794 if (LauncherModel.UPGRADE_USE_MORE_APPS_FOLDER) {
4795 getHotseat().addAllAppsFolder(mIconCache, apps,
4796 mIntentsOnWorkspaceFromUpgradePath, Launcher.this, mWorkspace);
4797 }
4798 mIntentsOnWorkspaceFromUpgradePath = null;
4799 }
4800 if (mAppsCustomizeContent != null) {
4801 mAppsCustomizeContent.onPackagesUpdated(
4802 LauncherModel.getSortedWidgetsAndShortcuts(this));
4803 }
4804 } else {
4805 if (mAppsCustomizeContent != null) {
4806 mAppsCustomizeContent.setApps(apps);
4807 mAppsCustomizeContent.onPackagesUpdated(
4808 LauncherModel.getSortedWidgetsAndShortcuts(this));
4809 }
4810 }
4811 }
4812
4813 /**
4814 * A package was updated.
4815 *
4816 * Implementation of the method from LauncherModel.Callbacks.
4817 */
4818 public void bindAppsUpdated(final ArrayList<AppInfo> apps) {
4819 Runnable r = new Runnable() {
4820 public void run() {
4821 bindAppsUpdated(apps);
4822 }
4823 };
4824 if (waitUntilResume(r)) {
4825 return;
4826 }
4827
4828 if (mWorkspace != null) {
4829 mWorkspace.updateShortcutsAndWidgets(apps);
4830 }
4831
4832 if (!LauncherAppState.isDisableAllApps() &&
4833 mAppsCustomizeContent != null) {
4834 mAppsCustomizeContent.updateApps(apps);
4835 }
4836 }
4837
4838 /**
4839 * Packages were restored
4840 */
4841 public void bindAppsRestored(final ArrayList<AppInfo> apps) {
4842 Runnable r = new Runnable() {
4843 public void run() {
4844 bindAppsRestored(apps);
4845 }
4846 };
4847 if (waitUntilResume(r)) {
4848 return;
4849 }
4850
4851 if (mWorkspace != null) {
4852 mWorkspace.updateShortcutsAndWidgets(apps);
4853 }
4854 }
4855
4856 /**
4857 * Update the state of a package, typically related to install state.
4858 *
4859 * Implementation of the method from LauncherModel.Callbacks.
4860 */
4861 @Override
4862 public void updatePackageState(ArrayList<PackageInstallInfo> installInfo) {
4863 if (mWorkspace != null) {
4864 mWorkspace.updatePackageState(installInfo);
4865 }
4866 }
4867
4868 /**
4869 * Update the label and icon of all the icons in a package
4870 *
4871 * Implementation of the method from LauncherModel.Callbacks.
4872 */
4873 @Override
4874 public void updatePackageBadge(String packageName) {
4875 if (mWorkspace != null) {
4876 mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle());
4877 }
4878 }
4879
4880 /**
4881 * A package was uninstalled. We take both the super set of packageNames
4882 * in addition to specific applications to remove, the reason being that
4883 * this can be called when a package is updated as well. In that scenario,
4884 * we only remove specific components from the workspace, where as
4885 * package-removal should clear all items by package name.
4886 *
4887 * Implementation of the method from LauncherModel.Callbacks.
4888 */
4889 public void bindComponentsRemoved(final ArrayList<String> packageNames,
4890 final ArrayList<AppInfo> appInfos, final UserHandleCompat user) {
4891 Runnable r = new Runnable() {
4892 public void run() {
4893 bindComponentsRemoved(packageNames, appInfos, user);
4894 }
4895 };
4896 if (waitUntilResume(r)) {
4897 return;
4898 }
4899
4900 if (!packageNames.isEmpty()) {
4901 mWorkspace.removeItemsByPackageName(packageNames, user);
4902 }
4903 if (!appInfos.isEmpty()) {
4904 mWorkspace.removeItemsByApplicationInfo(appInfos, user);
4905 }
4906
4907 // Notify the drag controller
4908 mDragController.onAppsRemoved(packageNames, appInfos);
4909
4910 // Update AllApps
4911 if (!LauncherAppState.isDisableAllApps() &&
4912 mAppsCustomizeContent != null) {
4913 mAppsCustomizeContent.removeApps(appInfos);
4914 }
4915 }
4916
4917 /**
4918 * A number of packages were updated.
4919 */
4920 private ArrayList<Object> mWidgetsAndShortcuts;
4921 private Runnable mBindPackagesUpdatedRunnable = new Runnable() {
4922 public void run() {
4923 bindPackagesUpdated(mWidgetsAndShortcuts);
4924 mWidgetsAndShortcuts = null;
4925 }
4926 };
4927 public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
4928 if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
4929 mWidgetsAndShortcuts = widgetsAndShortcuts;
4930 return;
4931 }
4932
4933 // Update the widgets pane
4934 if (mAppsCustomizeContent != null) {
4935 mAppsCustomizeContent.onPackagesUpdated(widgetsAndShortcuts);
4936 }
4937 }
4938
4939 private int mapConfigurationOriActivityInfoOri(int configOri) {
4940 final Display d = getWindowManager().getDefaultDisplay();
4941 int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
4942 switch (d.getRotation()) {
4943 case Surface.ROTATION_0:
4944 case Surface.ROTATION_180:
4945 // We are currently in the same basic orientation as the natural orientation
4946 naturalOri = configOri;
4947 break;
4948 case Surface.ROTATION_90:
4949 case Surface.ROTATION_270:
4950 // We are currently in the other basic orientation to the natural orientation
4951 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
4952 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
4953 break;
4954 }
4955
4956 int[] oriMap = {
4957 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
4958 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
4959 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
4960 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
4961 };
4962 // Since the map starts at portrait, we need to offset if this device's natural orientation
4963 // is landscape.
4964 int indexOffset = 0;
4965 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
4966 indexOffset = 1;
4967 }
4968 return oriMap[(d.getRotation() + indexOffset) % 4];
4969 }
4970
4971 public boolean isRotationEnabled() {
4972 boolean enableRotation = sForceEnableRotation ||
4973 getResources().getBoolean(R.bool.allow_rotation);
4974 return enableRotation;
4975 }
4976 public void lockScreenOrientation() {
4977 if (isRotationEnabled()) {
4978 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources()
4979 .getConfiguration().orientation));
4980 }
4981 }
4982 public void unlockScreenOrientation(boolean immediate) {
4983 if (isRotationEnabled()) {
4984 if (immediate) {
4985 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4986 } else {
4987 mHandler.postDelayed(new Runnable() {
4988 public void run() {
4989 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
4990 }
4991 }, mRestoreScreenOrientationDelay);
4992 }
4993 }
4994 }
4995
4996 /**
4997 * Called when the SearchBar hint should be changed.
4998 *
4999 * @param hint the hint to be displayed in the search bar.
5000 */
5001 protected void onSearchBarHintChanged(String hint) {
5002
5003 <<<<<<< LEFT
5004
5005
5006 ||||||| BASE
5007 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
5008 =======
5009
5010 mLauncherClings.updateSearchBarHint(hint);
5011
5012 >>>>>>> RIGHT
5013 }
5014
5015 protected boolean isLauncherPreinstalled() {
5016 PackageManager pm = getPackageManager();
5017 try {
5018 ApplicationInfo ai = pm.getApplicationInfo(getComponentName().getPackageName(), 0);
5019 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
5020 return true;
5021 } else {
5022 return false;
5023 }
5024 } catch (NameNotFoundException e) {
5025 e.printStackTrace();
5026 return false;
5027 }
5028 }
5029
5030 /**
5031 * This method indicates whether or not we should suggest default wallpaper dimensions
5032 * when our wallpaper cropper was not yet used to set a wallpaper.
5033 */
5034 protected boolean overrideWallpaperDimensions() {
5035 return true;
5036 }
5037
5038 protected boolean shouldClingFocusHotseatApp() {
5039 return false;
5040 }
5041 protected String getFirstRunClingSearchBarHint() {
5042 return "";
5043 }
5044 protected String getFirstRunCustomContentHint() {
5045 return "";
5046 }
5047 protected int getFirstRunFocusedHotseatAppDrawableId() {
5048 return -1;
5049 }
5050 protected ComponentName getFirstRunFocusedHotseatAppComponentName() {
5051 return null;
5052 }
5053 protected int getFirstRunFocusedHotseatAppRank() {
5054 return -1;
5055 }
5056 protected String getFirstRunFocusedHotseatAppBubbleTitle() {
5057 return "";
5058 }
5059 protected String getFirstRunFocusedHotseatAppBubbleDescription() {
5060 return "";
5061 }
5062
5063
5064 <<<<<<< LEFT
5065 /**
5066 * To be overridden by subclasses to indicate that there is an activity to launch
5067 * before showing the standard launcher experience.
5068 */
5069 protected boolean hasFirstRunActivity() {
5070 return false;
5071 }
5072
5073 /**
5074 * To be overridden by subclasses to launch any first run activity
5075 */
5076 protected Intent getFirstRunActivity() {
5077 return null;
5078 }
5079
5080 private boolean shouldRunFirstRunActivity() {
5081 return !ActivityManager.isRunningInTestHarness() &&
5082 !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5083 }
5084
5085 protected boolean hasRunFirstRunActivity() {
5086 return mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false);
5087 }
5088
5089 public boolean showFirstRunActivity() {
5090 if (shouldRunFirstRunActivity() &&
5091 hasFirstRunActivity()) {
5092 Intent firstRunIntent = getFirstRunActivity();
5093 if (firstRunIntent != null) {
5094 startActivity(firstRunIntent);
5095 markFirstRunActivityShown();
5096 return true;
5097 }
5098 }
5099 return false;
5100 }
5101
5102 private void markFirstRunActivityShown() {
5103 SharedPreferences.Editor editor = mSharedPrefs.edit();
5104 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
5105 editor.apply();
5106
5107 ||||||| BASE
5108 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
5109 =======
5110
5111 public void dismissFirstRunCling(View v) {
5112 mLauncherClings.dismissFirstRunCling(v);
5113 }
5114 public void dismissMigrationClingCopyApps(View v) {
5115 mLauncherClings.dismissMigrationClingCopyApps(v);
5116 }
5117 public void dismissMigrationClingUseDefault(View v) {
5118 mLauncherClings.dismissMigrationClingUseDefault(v);
5119 }
5120 public void dismissMigrationWorkspaceCling(View v) {
5121 mLauncherClings.dismissMigrationWorkspaceCling(v);
5122
5123 >>>>>>> RIGHT
5124 }
5125
5126 <<<<<<< LEFT
5127
5128 /**
5129 * To be overridden by subclasses to indicate that there is an in-activity full-screen intro
5130 * screen that must be displayed and dismissed.
5131 */
5132 protected boolean hasDismissableIntroScreen() {
5133 return false;
5134 }
5135
5136 /**
5137 * Full screen intro screen to be shown and dismissed before the launcher can be used.
5138 */
5139 protected View getIntroScreen() {
5140 return null;
5141 }
5142
5143 /**
5144 * To be overriden by subclasses to indicate whether the in-activity intro screen has been
5145 * dismissed. This method is ignored if #hasDismissableIntroScreen returns false.
5146 */
5147 private boolean shouldShowIntroScreen() {
5148 return hasDismissableIntroScreen() &&
5149 !mSharedPrefs.getBoolean(INTRO_SCREEN_DISMISSED, false);
5150 }
5151
5152 protected void showIntroScreen() {
5153 View introScreen = getIntroScreen();
5154 changeWallpaperVisiblity(false);
5155 if (introScreen != null) {
5156 mDragLayer.showOverlayView(introScreen);
5157 }
5158
5159 ||||||| BASE
5160 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
5161 =======
5162
5163 public void dismissWorkspaceCling(View v) {
5164 mLauncherClings.dismissWorkspaceCling(v);
5165
5166 >>>>>>> RIGHT
5167 }
5168
5169 <<<<<<< LEFT
5170
5171 public void dismissIntroScreen() {
5172 markIntroScreenDismissed();
5173 if (showFirstRunActivity()) {
5174 // We delay hiding the intro view until the first run activity is showing. This
5175 // avoids a blip.
5176 mWorkspace.postDelayed(new Runnable() {
5177 @Override
5178 public void run() {
5179 mDragLayer.dismissOverlayView();
5180 showFirstRunClings();
5181 }
5182 }, ACTIVITY_START_DELAY);
5183 } else {
5184 mDragLayer.dismissOverlayView();
5185 showFirstRunClings();
5186 }
5187 changeWallpaperVisiblity(true);
5188 }
5189
5190 private void markIntroScreenDismissed() {
5191 SharedPreferences.Editor editor = mSharedPrefs.edit();
5192 editor.putBoolean(INTRO_SCREEN_DISMISSED, true);
5193 editor.apply();
5194 }
5195
5196 private void showFirstRunClings() {
5197 // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
5198 // on the device, then we always show the first run cling experience (or if there is no
5199 // launcher2). Otherwise, we prompt the user upon started for migration
5200 LauncherClings launcherClings = new LauncherClings(this);
5201 if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
5202 if (mModel.canMigrateFromOldLauncherDb(this)) {
5203 launcherClings.showMigrationCling();
5204 } else {
5205 launcherClings.showLongPressCling(true);
5206 }
5207 }
5208 }
5209
5210 void showWorkspaceSearchAndHotseat() {
5211 if (mWorkspace != null) mWorkspace.setAlpha(1f);
5212 if (mHotseat != null) mHotseat.setAlpha(1f);
5213 if (mPageIndicators != null) mPageIndicators.setAlpha(1f);
5214 if (mSearchDropTargetBar != null) mSearchDropTargetBar.showSearchBar(false);
5215 }
5216
5217 void hideWorkspaceSearchAndHotseat() {
5218 if (mWorkspace != null) mWorkspace.setAlpha(0f);
5219 if (mHotseat != null) mHotseat.setAlpha(0f);
5220 if (mPageIndicators != null) mPageIndicators.setAlpha(0f);
5221 if (mSearchDropTargetBar != null) mSearchDropTargetBar.hideSearchBar(false);
5222
5223 ||||||| BASE
5224 /*d94z9sk0k4hf9j3ijd - note the base isn't actually empty, spork simply doesn't generate a base - gd930kw🔵
5225 =======
5226
5227 public void dismissFolderCling(View v) {
5228 mLauncherClings.dismissFolderCling(v);
5229
5230 >>>>>>> RIGHT
5231 }
5232
5233 private boolean shouldRunFirstRunActivity() {
5234 return !ActivityManager.isRunningInTestHarness();
5235 }
5236
5237 public void showFirstRunActivity() {
5238 if (shouldRunFirstRunActivity() && hasFirstRunActivity()
5239 && !mSharedPrefs.getBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, false)) {
5240 Intent firstRunIntent = getFirstRunActivity();
5241 if (firstRunIntent != null) {
5242 startActivity(firstRunIntent);
5243 markFirstRunActivityShown();
5244 }
5245 }
5246 }
5247
5248 private void markFirstRunActivityShown() {
5249 SharedPreferences.Editor editor = mSharedPrefs.edit();
5250 editor.putBoolean(FIRST_RUN_ACTIVITY_DISPLAYED, true);
5251 editor.apply();
5252 }
5253
5254 void showWorkspaceSearchAndHotseat() {
5255 mWorkspace.setAlpha(1f);
5256 mHotseat.setAlpha(1f);
5257 mPageIndicators.setAlpha(1f);
5258 mSearchDropTargetBar.showSearchBar(false);
5259 }
5260
5261 void hideWorkspaceSearchAndHotseat() {
5262 mWorkspace.setAlpha(0f);
5263 mHotseat.setAlpha(0f);
5264 mPageIndicators.setAlpha(0f);
5265 mSearchDropTargetBar.hideSearchBar(false);
5266 }
5267
5268
5269 public ItemInfo createAppDragInfo(Intent appLaunchIntent) {
5270 // Called from search suggestion, not supported in other profiles.
5271 final UserHandleCompat myUser = UserHandleCompat.myUserHandle();
5272 LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(this);
5273 LauncherActivityInfoCompat activityInfo = launcherApps.resolveActivity(appLaunchIntent,
5274 myUser);
5275 if (activityInfo == null) {
5276 return null;
5277 }
5278 return new AppInfo(this, activityInfo, myUser, mIconCache, null);
5279 }
5280
5281 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5282 Bitmap icon) {
5283 // Called from search suggestion, not supported in other profiles.
5284 return createShortcutDragInfo(shortcutIntent, caption, icon,
5285 UserHandleCompat.myUserHandle());
5286 }
5287
5288 public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption,
5289 Bitmap icon, UserHandleCompat user) {
5290 UserManagerCompat userManager = UserManagerCompat.getInstance(this);
5291 CharSequence contentDescription = userManager.getBadgedLabelForUser(caption, user);
5292 return new ShortcutInfo(shortcutIntent, caption, contentDescription, icon, user);
5293 }
5294
5295 protected void moveWorkspaceToDefaultScreen() {
5296 mWorkspace.moveToDefaultScreen(false);
5297 }
5298
5299 public void startDrag(View dragView, ItemInfo dragInfo, DragSource source) {
5300 dragView.setTag(dragInfo);
5301 mWorkspace.onExternalDragStartedWithItem(dragView);
5302 mWorkspace.beginExternalDragShared(dragView, source);
5303 }
5304
5305 @Override
5306 public void onPageSwitch(View newPage, int newPageIndex) {
5307 }
5308
5309 /**
5310 * Prints out out state for debugging.
5311 */
5312 public void dumpState() {
5313 Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this);
5314 Log.d(TAG, "mSavedState=" + mSavedState);
5315 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
5316 Log.d(TAG, "mRestoring=" + mRestoring);
5317 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
5318 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
5319 Log.d(TAG, "sFolders.size=" + sFolders.size());
5320 mModel.dumpState();
5321
5322 if (mAppsCustomizeContent != null) {
5323 mAppsCustomizeContent.dumpState();
5324 }
5325 Log.d(TAG, "END launcher3 dump state");
5326 }
5327
5328 @Override
5329 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
5330 super.dump(prefix, fd, writer, args);
5331 synchronized (sDumpLogs) {
5332 writer.println(" ");
5333 writer.println("Debug logs: ");
5334 for (int i = 0; i < sDumpLogs.size(); i++) {
5335 writer.println(" " + sDumpLogs.get(i));
5336 }
5337 }
5338 }
5339
5340 public static void dumpDebugLogsToConsole() {
5341 if (DEBUG_DUMP_LOG) {
5342 synchronized (sDumpLogs) {
5343 Log.d(TAG, "");
5344 Log.d(TAG, "*********************");
5345 Log.d(TAG, "Launcher debug logs: ");
5346 for (int i = 0; i < sDumpLogs.size(); i++) {
5347 Log.d(TAG, " " + sDumpLogs.get(i));
5348 }
5349 Log.d(TAG, "*********************");
5350 Log.d(TAG, "");
5351 }
5352 }
5353 }
5354
5355 public static void addDumpLog(String tag, String log, boolean debugLog) {
5356 addDumpLog(tag, log, null, debugLog);
5357 }
5358
5359 public static void addDumpLog(String tag, String log, Exception e, boolean debugLog) {
5360 if (debugLog) {
5361 if (e != null) {
5362 Log.d(tag, log, e);
5363 } else {
5364 Log.d(tag, log);
5365 }
5366 }
5367 if (DEBUG_DUMP_LOG) {
5368 sDateStamp.setTime(System.currentTimeMillis());
5369 synchronized (sDumpLogs) {
5370 sDumpLogs.add(sDateFormat.format(sDateStamp) + ": " + tag + ", " + log
5371 + (e == null ? "" : (", Exception: " + e)));
5372 }
5373 }
5374 }
5375
5376 public void dumpLogsToLocalData() {
5377 if (DEBUG_DUMP_LOG) {
5378 new AsyncTask<Void, Void, Void>() {
5379 public Void doInBackground(Void ... args) {
5380 boolean success = false;
5381 sDateStamp.setTime(sRunStart);
5382 String FILENAME = sDateStamp.getMonth() + "-"
5383 + sDateStamp.getDay() + "_"
5384 + sDateStamp.getHours() + "-"
5385 + sDateStamp.getMinutes() + "_"
5386 + sDateStamp.getSeconds() + ".txt";
5387
5388 FileOutputStream fos = null;
5389 File outFile = null;
5390 try {
5391 outFile = new File(getFilesDir(), FILENAME);
5392 outFile.createNewFile();
5393 fos = new FileOutputStream(outFile);
5394 } catch (Exception e) {
5395 e.printStackTrace();
5396 }
5397 if (fos != null) {
5398 PrintWriter writer = new PrintWriter(fos);
5399
5400 writer.println(" ");
5401 writer.println("Debug logs: ");
5402 synchronized (sDumpLogs) {
5403 for (int i = 0; i < sDumpLogs.size(); i++) {
5404 writer.println(" " + sDumpLogs.get(i));
5405 }
5406 }
5407 writer.close();
5408 }
5409 try {
5410 if (fos != null) {
5411 fos.close();
5412 success = true;
5413 }
5414 } catch (IOException e) {
5415 e.printStackTrace();
5416 }
5417 return null;
5418 }
5419 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
5420 }
5421 }
5422 }
5423
5424 interface LauncherTransitionable {
5425 public abstract View getContent();
5426
5427 public abstract void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace);
5428
5429 public abstract void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace);
5430
5431 public abstract void onLauncherTransitionStep(Launcher l, float t);
5432
5433 public abstract void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace);
5434 }
|